Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPretender and setPretender functions as public exports #338

Merged
merged 2 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import FactoryGuy, {
import {
mockSetup, mockTeardown,
mockFind, mockFindRecord, mockFindAll, mockReload, mockQuery,
mockQueryRecord, mockCreate, mockUpdate, mockDelete, mock, mockLinks
mockQueryRecord, mockCreate, mockUpdate, mockDelete, mock, mockLinks,
getPretender
} from './mocks/exposed-request-functions';

import manualSetup from './utils/manual-setup';
Expand All @@ -30,7 +31,8 @@ export { make, makeNew, makeList, build, buildList, attributesFor, manualSetup,
export {
mockSetup, mockTeardown,
mockFind, mockFindRecord, mockFindAll, mockReload, mockQuery,
mockQueryRecord, mockCreate, mockUpdate, mockDelete, mock, mockLinks
mockQueryRecord, mockCreate, mockUpdate, mockDelete, mock, mockLinks,
getPretender
};

export function setupFactoryGuy(hooks) {
Expand Down
8 changes: 8 additions & 0 deletions addon/mocks/exposed-request-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MockFindAllRequest from './mock-find-all-request';
import MockDeleteRequest from './mock-delete-request';
import MockAnyRequest from './mock-any-request';
import MockLinksRequest from './mock-links-request';
import RequestManager from './request-manager';

export function mockSetup({responseTime, logLevel = 0} = {}) {
Ember.deprecate(`[ember-data-factory-guy] mockSetup is no longer needed. If you want to set logLevel or responseTime, use FactoryGuy.settings instead. If you don't need to set anything, it is safe to remove mockSetup`,
Expand Down Expand Up @@ -384,3 +385,10 @@ export function mockDelete(...args) {

return new MockDeleteRequest(modelName, id);
}

/**
Returns the Pretender instance used for the mocks.
*/
export function getPretender() {
return RequestManager.getPretender();
}
22 changes: 22 additions & 0 deletions tests/unit/get-pretenter-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { mock, manualSetup, getPretender } from 'ember-data-factory-guy';
import Pretender from 'pretender'

module('Unit | getPretender', function(hooks) {
setupTest(hooks);

hooks.beforeEach(function() {
manualSetup(this);
});

test('getPretender basic usage', function(assert) {
assert.expect(3);
let pretender = getPretender();

assert.ok(pretender instanceof Pretender, "getPretender returns an instance of Pretender");
assert.equal(pretender.handlers.length, 0, "the handlers array is initially empty");
mock({url: "/api/whatever"});
assert.equal(pretender.handlers.length, 1, "the created mock is added to the handlers");
});
});