Given-when-then syntax reference
Verifier is based on JsTestDriver and includes an extended version of the Jasmine BDD framework. The reference list below highlights the main feature syntax of Jasmine and our extensions of the framework.
Test Related Syntax
given
As in "Given a system is in an initial state".
given("tile.opened = true");
when
As in "When a system state change is made".
when("tile.buyButton.clicked => true");
then
As in "Then a system will be in a new state".
then("tile.opened = false");
continuesFrom
A test can continue from another test. This allows a set of previous state changes to be included in the current test without having to include them all as individual lines in the current test. This allows efficient re-use of previous test cases. However, beware that this doesn’t lead to unnecessary chaining of tests, as this can make them difficult to read and debug.
given("test.continuesFrom = 'tile trade test'");
it
As in "(test that) it". Each test within a suite begins with it.
it("is in the initial state when the tile is opened", function(){
xit
As in "exclude test". Use this to exclude an individual test, but note that we can still continue from the test, and be informed of the excluded test in the test results.
xit("is in the initial state when the tile is opened", function(){
=
This is used in given
and then
statements to check that values have been set correctly. N.B. You must leave a space on each side of the = sign or the test will fail.
then("tile.state = 'opened'");
=>
This syntax is used in when
statements, to set a value.
when("tile.state => 'opened'");
and
Indicates that more than one clause needs to be checked for this part of the test.
given("tile.opened = true"); and("tile.tradeState = initial");
Or
then("tile.opened=false"); and("tile.tradeState = 'final'");
Suite Related Syntax
describe
Each test suite has a describe which indicates the name of the test suite.
describe("tile trade test" , function() {
xdescribe
To exclude an entire suite of tests from the test run.
xdescribe("tile trade test" , function() {
fixtures
Used to include any fixtures required by the test suite.
fixtures("ViewFixtureTestsFixtureFactory");
Or
fixtures("caplin.component.testing.TreeComponentFixtureFactory");
beforeEach
An optional function to run some setup tasks before each test suite is run. This could call another function to perform the setup tasks.
beforeEach(function() {
setupPage()
});
Or, if there are only one or two setup tasks these can be placed within this function.
beforeEach(function () {
caplin.testing.Utils.loadCSSAndAttachToPage(["/test/resources/unbundled-style/reset.css", "/test/bundles/css/common_css.bundle"]);
caplin.testing.Utils.captureSetIntervalAndSetTimeout();
});
afterEach
An optional function to run some teardown tasks after each test suite is run. This could call another function to perform the setup tasks.
afterEach(function() {
tearDownPage();
});
Or, if there are only one or two setup tasks these can be placed within this function.
afterEach(function () {
caplin.testing.Utils.removeLoadedAndAttachedCSSFromPage();
caplin.testing.Utils.getCapturedFunctionsAndReleaseSetIntervalAndSetTimeout();
});