A10 comes with v3.5; Jasmine is a fairly straightforward bdd framework, has a sane list of matchers and fairly basic spy capabilities:
describe
(desc, specDefs)afterEach
, afterAll
(fn opt, timeout opt)beforeEach
, beforeAll
(fn opt, timeout opt)it
(desc, fn opt, timeout opt)expect
(actual), expectAsync
(actual)fdescribe
, fit
xdescribe
, xit
Negation modifier is .not.
expect(thing).toBe(realThing);
expect(bigObject).toEqual({"foo": ['bar', 'baz']});
expect(result).toBeDefined();
expect(result).toBeUndefined():
expect(result).toBeTruthy();
expect(result).toBeFalsy();
expect(result).toBeTrue();
expect(result).toBeFalse();
expect(thing).toBeNaN();
expect(number).toBeCloseTo(42.2, 3);
expect(number).toBeGreaterThan(3);
expect(number).toBeGreaterThanOrEqual(25);
expect(number).toBeLessThan(0);
expect(number).toBeLessThanOrEqual(123);
expect(number).toBeNegativeInfinity();
expect(number).toBePositiveInfinity();
expect(string).toContain(substring);
expect("my string").toMatch(/string$/);
expect(array).toContain(anElement);
expect(result).toBeNull();
expect(result).toBeInstanceOf(String);
expect(htmlEl).toHaveClass('bar'); //css
expect(() => { return 'x'; }).toThrow();
expect(() => { return 'x'; }).toThrowError();
expect(() => { return 'x'; }).toThrowMatching(predicateFn)
expectAsync(aPromise).toBeResolved();
expectAsync(aPromise).toBeResolvedTo({prop: 'value'});
expectAsync(aPromise).toBeRejected();
expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
expectAsync(aPromise).toBeRejectedWithError(MyError, /message/);
Future 3.6:
Spy naming (aName
) is optional, like most other parameters (lots of 🦆 typing).
spyOn(obj, methodName)
spyOnProperty(obj, propName, 'get'/'set')
spyOnAllFunctions(obj)
jasmine.createSpy(aName, fn)
jasmine.createSpyObj(aName, [ methods ], [ props ])
.and
to start a "strategy"):.and.stub
is the default, which does nothing.and.returnValue(42)
, .and.returnValues(first)
.and.resolveTo(aPromise)
.and.callFake(x => x)
.withArgs(1, 2, 3).and.
expect(mySpy).toHaveBeenCalled();
expect(mySpy).toHaveBeenCalledBefore(otherSpy);
expect(mySpy).toHaveBeenCalledTimes(3);
expect(mySpy).toHaveBeenCalledWith('foo', 'bar', 2);
expect(mySpy).toHaveBeenNthCalledWith(1, data);
mySpy.calls.reset()