1.0.0 • Published 9 years ago

ember-cli-jsmockito v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Ember-cli-jsmockito

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('user@domain.com', 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);

Mock functions - docs

var mockedFunc = mockFunction();

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 mockedFunc = mockFunction();
mockedFunc('hello world');
verify(mockedFunc)('hello world');
  • Visit JsMockito for more information about mocking.
  • Visit JsHamcrest for more information about the matching.