ember-aupac-mocks

1.0.1 • Public • Published

Ember-aupac-mocks

NPM package Build Status Ember Observer Score

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

Requirements

ember-cli >= 1.13.x

Installing

ember install ember-aupac-mocks

Usage

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('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)));
});

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);

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;

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.11
1.0.00

Package Sidebar

Install

npm i ember-aupac-mocks

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • aupac