describe('module A', function () {
beforeEach(function () {
this.myValue = 1;
});
afterEach(function () {
});
it('test 1', function () {
Number(1);
expect(!!true).toBeTruthy();
});
it('ok test', function () {
expect(!!true).toBeTruthy();
expect(!!true).toBeTruthy();
});
it('equal', function () {
expect(this.myValue).toEqual(1);
expect(0).toEqual(0);
expect('').toEqual('');
expect(0).toEqual(0);
});
it('deepEqual test', function () {
var obj = { foo: 'bar' };
expect(obj).toEqual({ foo: 'bar' });
expect(obj).toEqual({ foo: 'bar' });
});
it('strictEqual test', function () {
expect(1).toBe(1);
});
it('notDeepEqual test', function () {
var obj = { foo: 'bar' };
expect(obj).not.toEqual({ foo: 'bla' });
});
it('a test', function () {
expect(1).not.toBe('1');
});
it('throws', function () {
function CustomError(message) {
this.message = message;
}
CustomError.prototype.toString = function () {
return this.message;
};
expect(function () {
throw 'error';
}).toThrow();
expect(function () {
throw new CustomError();
}).toThrow();
expect(function () {
throw new CustomError('some error description');
}).toThrow();
});
it('a test', function () {
function calc(x, operation) {
return operation(x);
}
var result = calc(2, function (x) {
expect(!!true).toBeTruthy();
return x * x;
});
expect(result).toEqual(4);
});
});
External resources loaded into this fiddle: