TestCafe v2015.1   |   Documentation
The documentation on this webpage describes TestCafe v2015.1. This product is no longer available and has been replaced by TestCafe Studio. TestCafe Studio is our new cross-platform IDE for end-to-end web testing.
To learn more about TestCafe Studio, please visit www.devexpress.com/testcafestudio

ASSERTIONS

Using TestCafe assertions, you can check whether an arbitrary expression resolves to true or false, or whether two objects are equal or different.

ok

Checks if the specified expression is true.

ok( expression [, message] ) 

expression - Object (required). Use this parameter to specify an expression to be tested. If the expression resolves to true, the assertion passes. Otherwise, the test fails.
message - String (optional). This text identifies the assertion in the error log if the expression resolves to false and the test fails.

The following code snippet demonstrates various expressions with the corresponding assertion results.

ok(true, "true succeeds");
ok(false, "false fails");
ok("non-empty", "non-empty string succeeds");
ok("", "empty string fails");
ok(0, "0 fails");
ok(NaN, "NaN fails");
ok(null, "null fails");
ok(undefined, "undefined fails");

The following example checks if an editor is initially disabled and becomes enabled after a check box is clicked. (TestCafe Example Page)

'@test'['Check Enabled State'] = {
    'Check disabled': function () {
        ok($('#Developer_Comments').is(':disabled'));
    },
    'Click label "I have tried TestCafe"': function () {
        var label = $(':containsExcludeChildren(I have tried TestCafe)');
        act.click(label);
    },
    'Check enabled': function () {
        notOk($('#Developer_Comments').is(':disabled'));
    }
};

notOk

Checks if the specified expression is false.

notOk( expression [, message] ) 

expression - Object (required). Use this parameter to specify an expression to be tested. If the expression resolves to false, the assertion passes. Otherwise, the test fails.
message - String (optional). This text identifies the assertion in the error log if the expression resolves to true and the test fails.

The following code snippet demonstrates various expressions with the corresponding assertion results.

notOk(false, "false succeeds");
notOk(true, "true fails");
notOk("", "empty string succeeds");
notOk("non-empty", "non-empty string fails");
notOk(0, "0 succeeds");
notOk(NaN, "NaN succeeds");
notOk(null, "null succeeds");
notOk(undefined, "undefined succeeds");

The following example checks if an editor is initially disabled and becomes enabled after a check box is clicked. (TestCafe Example Page)

'@test'['Check Enabled State'] = {
    'Check disabled': function () {
        ok($('#Developer_Comments').is(':disabled'));
    },
    'Click label "I have tried TestCafe"': function () {
        var label = $(':containsExcludeChildren(I have tried TestCafe)');
        act.click(label);
    },
    'Check enabled': function () {
        notOk($('#Developer_Comments').is(':disabled'));
    }
};

eq

Checks whether or not two objects are equal. This assertion uses a deep recursive comparison that works on primitive types, arrays and objects.

eq( actual, expected [, message] ) 

actual, expected - Object (required). The objects that are being compared to each other. If the specified objects are different, the assertion fails.
message - String (optional). This text identifies the assertion in the error log if the objects are different and the test fails.

The following example checks to see if a survey's 'Thank You' page displays the proper message. (TestCafe Example Page)

'@test'['eq() Example'] = {
    'Type name': function () {
        act.type(getInput(), 'Peter Parker');
    },
    'Click "Submit"': function () {
        var submitButton = $('.button.blue.fix-width-180');
        act.click(submitButton);
    },
    'Check message': function () {
        var header = $('.article-header');
        eq(header.html(), 'Thank You, Peter Parker!');
    }
};

notEq

Checks whether or not two objects are different. This assertion uses a deep recursive comparison that works on primitive types, arrays and objects.

notEq( actual, unexpected [, message] ) 

actual, unexpected - Object (required). The objects that are being compared to each other. If the specified objects are the same, the assertion fails.
message - String (optional). This text identifies the assertion in the error log if the objects are identical and the test fails.