Skip to content

Commit

Permalink
test: fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
virkt25 committed Feb 15, 2018
1 parent b1492fc commit a65a192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/boot/test/integration/controller.booter.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
// License text available at https://opensource.org/licenses/MIT

import {expect, TestSandbox} from '@loopback/testlab';
import {CoreBindings} from '@loopback/core';
import {resolve} from 'path';
import {ControllerBooterApp} from '../fixtures/application';

describe('controller booter integration tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);

// Remnants from Refactor -- need to add these to core
const CONTROLLERS_PREFIX = 'controllers';
const CONTROLLERS_TAG = 'controller';

let app: ControllerBooterApp;

beforeEach(resetSandbox);
beforeEach(getApp);

it('boots controllers when app.boot() is called', async () => {
const expectedBindings = [
`${CoreBindings.CONTROLLERS_PREFIX}.ControllerOne`,
`${CoreBindings.CONTROLLERS_PREFIX}.ControllerTwo`,
`${CONTROLLERS_PREFIX}.ControllerOne`,
`${CONTROLLERS_PREFIX}.ControllerTwo`,
];

await app.boot();

const bindings = app
.findByTag(CoreBindings.CONTROLLERS_TAG)
.map(b => b.key);
const bindings = app.findByTag(CONTROLLERS_TAG).map(b => b.key);
expect(bindings.sort()).to.eql(expectedBindings.sort());
});

Expand Down
11 changes: 7 additions & 4 deletions packages/boot/test/unit/booters/controller.booter.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
// License text available at https://opensource.org/licenses/MIT

import {expect, TestSandbox} from '@loopback/testlab';
import {Application, CoreBindings} from '@loopback/core';
import {Application} from '@loopback/core';
import {ControllerBooter, ControllerDefaults} from '../../../index';
import {resolve} from 'path';

describe('controller booter unit tests', () => {
const SANDBOX_PATH = resolve(__dirname, '../../../.sandbox');
const sandbox = new TestSandbox(SANDBOX_PATH);

const CONTROLLERS_PREFIX = 'controllers';
const CONTROLLERS_TAG = 'controller';

let app: Application;

beforeEach(resetSandbox);
Expand All @@ -37,8 +40,8 @@ describe('controller booter unit tests', () => {

it('binds controllers during load phase', async () => {
const expected = [
`${CoreBindings.CONTROLLERS_PREFIX}.ControllerOne`,
`${CoreBindings.CONTROLLERS_PREFIX}.ControllerTwo`,
`${CONTROLLERS_PREFIX}.ControllerOne`,
`${CONTROLLERS_PREFIX}.ControllerTwo`,
];
await sandbox.copyFile(
resolve(__dirname, '../../fixtures/multiple.artifact.js'),
Expand All @@ -50,7 +53,7 @@ describe('controller booter unit tests', () => {
booterInst.discovered = [resolve(SANDBOX_PATH, 'multiple.artifact.js')];
await booterInst.load();

const ctrls = app.findByTag(CoreBindings.CONTROLLERS_TAG);
const ctrls = app.findByTag(CONTROLLERS_TAG);
const keys = ctrls.map(binding => binding.key);
expect(keys).to.have.lengthOf(NUM_CLASSES);
expect(keys.sort()).to.eql(expected.sort());
Expand Down

0 comments on commit a65a192

Please sign in to comment.