Suite Groups
As we have seen before, the describe() function describes a test suite of related specs in a test bundle CFC. The title of the suite is concatenated with the title of a spec to create a full spec's name which is very descriptive. If you name them well, they will read out as full sentences as defined by BDD style.
1
describe("A spec", function() {
2
it("is just a closure, so it can contain any code", function() {
3
coldbox = 0;
4
coldbox++;
5
6
expect( coldbox ).toBe( 1 );
7
});
8
9
it("can have more than one expectation", function() {
10
coldbox = 0;
11
coldbox++;
12
13
expect( coldbox ).toBe( 1 );
14
expect( coldbox ).toBeTrue();
15
});
16
});
Copied!

Nesting describe Blocks

Calls to our describe() function can be nested with specs at any level or point of execution. This allows you to create your tests as a related tree of nested functions. Please note that before a spec is executed, TestBox walks down the tree executing each beforeEach() and afterEach() function in the declared order. This is a great way to logically group specs in any level as you see fit.
1
describe("A spec", function() {
2
3
beforeEach(function( currentSpec ) {
4
coldbox = 22;
5
application.wirebox = new coldbox.system.ioc.Injector();
6
});
7
8
afterEach(function( currentSpec ) {
9
coldbox = 0;
10
structDelete( application, "wirebox" );
11
});
12
13
it("is just a function, so it can contain any code", function() {
14
expect( coldbox ).toBe( 22 );
15
});
16
17
it("can have more than one expectation and talk to scopes", function() {
18
expect( coldbox ).toBe( 22 );
19
expect( application.wirebox.getInstance( 'MyService' ) ).toBeComponent();
20
});
21
22
describe("nested inside a second describe", function() {
23
24
beforeEach(function( currentSpec ) {
25
awesome = 22;
26
});
27
28
afterEach(function( currentSpec ) {
29
awesome = 22 + 8;
30
});
31
32
it("can reference both scopes as needed ", function() {
33
expect( coldbox ).toBe( awesome );
34
});
35
});
36
37
it("can be declared after nested suites and have access to nested variables", function() {
38
expect( awesome ).toBe( 30 );
39
});
40
41
});
Copied!
Copy link
Edit on GitHub