Intro to BDD Syntax
Kyle Coberly
kylecoberly.com
- Educator
- Business Dork
- Software Developer
Learning Objective:
Recall the 3 types of Chai particles
Test-First Development
TDD vs. BDD
assert.equal(sum(1, 1), 2)
expect(sum(1, 1)).to.equal(2)
System's Perspective
User's Perspective
What mindset does writing the test put you in?
Can non-technical people understand your assertions?
Chai
- Assertion Library
- Syntax for assert, expect, and should
-
Works with any test runner
expect Particles
- Chainers
- Assertions
- Flags
const people = [{
kyle: { name: "Kyle", height: 90 },
dusing: { name: "Dusing", height: 100 },
}]
const tallestPerson = { name: "Dusing", height: 100 }
expect(getTallest(people)).to.deep.equal(tallestPerson)
Chainer
Assertion
Flag
Chainers
-
to, be
-
have, has
-
a, an
-
and, but
Assertions
-
equal
-
property
-
a, an
-
true, false, ok, exist
-
empty
-
members, keys
-
include
-
lengthOf
Flags
-
not
-
deep
-
nested
-
ordered
expect(result).to.have.nested.property("key.nestedKey", "value")
expect(result).to.include("some sub string")
expect(result).to.have.keys(["key1", "key2"])
expect(result).to.have.all.members(["item 1", "item 2"])
expect(result).to.match(/[a-zA-Z]/)
expect(result).to.equal("some string")
expect(result).to.deep.equal({ message: "some string" })
expect(result).to.not.equal("some string")
expect(result).to.have.lengthOf(3)
Equality
Matching
Examples
Kyle Coberly
kylecoberly.com
Intro to BDD Syntax
By Kyle Coberly
Intro to BDD Syntax
Lightning talk for DenverScript 9/24/19
- 1,358