Skip to content

Latest commit

 

History

History
126 lines (111 loc) · 2.96 KB

README.md

File metadata and controls

126 lines (111 loc) · 2.96 KB

Ember-cli-jsmockito

WARNING: This project has now been superseded by ember-aupac-mocks, if using a version of ember-cli > 1.13.x use that library instead.

Javascript Mocking and Matching Library for unit testing ember-cli applications.

Requirements

ember-cli >= 0.1.4

Installing

npm install ember-cli-jsmockito --save-dev

Add the following to tests/.jshintrc inside the predef array.

    "mock",
    "when",
    "verify",
    "mockFunction",
    "spy",
    "verifyZeroInteractions",
    "verifyNoMoreInteractions",
    "isMock",
    "never",
    "zeroInteractions",
    "noMoreInteractions",
    "times",
    "once",
    "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"

Features

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.