Javascript Mocking and Matching Library for unit testing ember-cli applications.
ember-cli >= 1.13.x
ember install ember-aupac-mocks
Import the Mocks and Matchers into your ember test.
import { Mocks, Matchers } from 'ember-aupac-mocks';
//Use object deconstruction to pull out the features you want to use
const { mock, mockFunction, verify, when, ...more} = Mocks;
const { empty, emailAddress, greaterThan, everyItem, hasSize, even, lessThan, either, ...more} = Matchers;
//Start mocking and matching in your tests
test('mocking and matching', function(assert) {
const myMock = mock(Ember.Object);
when(myMock).get('name').thenReturn('hello world');
assert.equal('hello world', myMock.get('name'), 'should be the same');
verify(myMock).get('name');
assertThat('', empty());
assertThat('[email protected]', emailAddress());
assertThat(10, either(greaterThan(50)).or(even()));
assertThat([1,2,3], everyItem(greaterThan(0)));
assertThat([1,2,3], hasSize(lessThan(5)));
});
Rich and readable matching api - docs
assertThat('', empty());
assertThat('[email protected]', emailAddress());
assertThat(10, either(greaterThan(50)).or(even()));
assertThat([1,2,3], everyItem(greaterThan(0)));
assertThat([1,2,3], hasSize(lessThan(5)));
Mock any object - docs
var modelMock = mock(DS.Model);
var controllerMock = mock(Ember.Controller);
Setup expectations on your mocks - docs
var employeeMock = mock(DS.Model);
when(employeeMock).get('name').thenReturn('jack');
equal('jack',employeeMock.get('name'));
Verify function execution - docs
var employeeMock = mock(DS.Model);
employeeMock.get('name');
verify(employeeMock).get("name");
Mock functions - docs
var mockedFunc = mockFunction();
Verify function execution - docs
var mockedFunc = mockFunction();
mockedFunc('hello world');
verify(mockedFunc)('hello world');
- Visit JsMockito for more information about mocking.
- Visit JsHamcrest for more information about the matching.
Mocks - docs
const {
mock,
when,
verify,
mockFunction,
spy,
verifyZeroInteractions,
verifyNoMoreInteractions,
isMock,
never,
zeroInteractions,
noMoreInteractions,
times,
once
} = Mocks;
Matchers - docs
const {
assertThat,
empty,
everyItem,
hasItem,
hasItems,
hasSize,
isIn,
oneOf,
allOf,
anyOf,
anything,
both,
either,
equalTo,
is,
nil,
not,
raises,
raisesAnything,
sameAs,
truth,
equivalentMap,
equivalentArray,
between,
closeTo,
divisibleBy,
even,
greaterThan,
greaterThanOrEqualTo,
lessThan,
lessThanOrEqualTo,
notANumber,
odd,
zero,
bool,
func,
hasFunction,
hasMember,
instanceOf,
number,
object,
string,
typeOf,
containsString,
emailAddress,
endsWith,
equalIgnoringCase,
matches,
startsWith,
filter,
callTo
} = Matchers;
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.