angular.js/test/scenario/matchersSpec.js
Elliott Sprehn 03df6cbddb New Angular Scenario runner and DSL system with redesigned HTML UI.
Uses the Jasmine syntax for tests, ex:

describe('widgets', function() {
  it('should verify that basic widgets work', function(){
    navigateTo('widgets.html');
    input('text.basic').enter('Carlos');
    expect(binding('text.basic')).toEqual('Carlos');
    input('text.basic').enter('Carlos Santana');
    expect(binding('text.basic')).not().toEqual('Carlos Boozer');
    input('text.password').enter('secret');
    expect(binding('text.password')).toEqual('secret');
    expect(binding('text.hidden')).toEqual('hiddenValue');
    expect(binding('gender')).toEqual('male');
    input('gender').select('female');
    expect(binding('gender')).toEqual('female');
  });
});

Note: To create new UI's implement the interface shown in angular.scenario.ui.Html.
2010-10-14 09:47:39 -07:00

43 lines
1.4 KiB
JavaScript

describe('angular.scenario.matchers', function () {
var matchers;
function expectMatcher(value, test) {
delete matchers.error;
delete matchers.future.value;
if (value !== undefined) {
matchers.future.value = value;
}
test();
expect(matchers.error).toBeUndefined();
}
beforeEach(function() {
/**
* Mock up the future system wrapped around matchers.
*
* @see Scenario.js#angular.scenario.matcher
*/
matchers = {
future: { name: 'test' }
};
matchers.addFuture = function(name, callback) {
callback(function(error) {
matchers.error = error;
});
};
angular.extend(matchers, angular.scenario.matcher);
});
it('should handle basic matching', function() {
expectMatcher(10, function() { matchers.toEqual(10); });
expectMatcher('value', function() { matchers.toBeDefined(); });
expectMatcher([1], function() { matchers.toBeTruthy(); });
expectMatcher("", function() { matchers.toBeFalsy(); });
expectMatcher(0, function() { matchers.toBeFalsy(); });
expectMatcher('foo', function() { matchers.toMatch('.o.'); });
expectMatcher(null, function() { matchers.toBeNull(); });
expectMatcher([1, 2, 3], function() { matchers.toContain(2); });
expectMatcher(3, function() { matchers.toBeLessThan(10); });
expectMatcher(3, function() { matchers.toBeGreaterThan(-5); });
});
});