Skip to content

Commit

Permalink
unit tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Jan 16, 2016
1 parent d6b588e commit a15f7db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
1 change: 0 additions & 1 deletion lib/realm.js
@@ -1,5 +1,4 @@
'use strict'

const merge = require('merge')

module.exports = function(remi, opts) {
Expand Down
40 changes: 16 additions & 24 deletions test/index.js
Expand Up @@ -9,11 +9,17 @@ const Remi = require('../')
chai.use(sinonChai)

describe('Remi', function() {
let app
let remi

beforeEach(function() {
app = {}
remi = new Remi()
})

it('should register plugin with no version', function() {
let plugin = plugiator.anonymous((app, options, next) => next())

let remi = new Remi()
let app = {}
return remi
.register(app, { register: plugin })
.then(() => {
Expand All @@ -24,8 +30,6 @@ describe('Remi', function() {
it('should register synchronous plugin', function() {
let plugin = plugiator.anonymous((app, opts) => {})

let remi = new Remi()
let app = {}
return remi
.register(app, { register: plugin })
.then(() => {
Expand All @@ -36,8 +40,6 @@ describe('Remi', function() {
it('should register plugin that returns a promise', function() {
let plugin = plugiator.anonymous((app, opts) => Promise.resolve())

let remi = new Remi()
let app = {}
return remi.register(app, { register: plugin })
.then(() => {
expect(app.registrations[plugin.attributes.name]).to.exist
Expand All @@ -49,9 +51,8 @@ describe('Remi', function() {
let plugin = plugiator.anonymous(register)
let pluginOpts = { something: true }

let remi = new Remi()
return remi
.register({}, { register: plugin, options: pluginOpts })
.register(app, { register: plugin, options: pluginOpts })
.then(() => {
expect(register).to.have.been.calledOnce
expect(register.args[0][1]).to.eql(pluginOpts)
Expand All @@ -65,7 +66,6 @@ describe('Remi', function() {
dependencies: ['foo'],
})

let remi = new Remi()
remi.register({}, plugin, function(err) {
expect(err).to.be.an.instanceof(Error)
done()
Expand Down Expand Up @@ -94,9 +94,8 @@ describe('Remi', function() {
before: ['plugin2'],
}))

let remi = new Remi()
return remi
.register({}, [plugin2, plugin1])
.register(app, [plugin2, plugin1])
.then(() => {
expect(plugin1).to.have.been.calledBefore(plugin2)
})
Expand All @@ -112,7 +111,6 @@ describe('Remi', function() {
version: '0.1.0',
})

let app = {}
let plugins = [
{
register: plugin1,
Expand All @@ -122,7 +120,6 @@ describe('Remi', function() {
register: plugin2,
},
]
let remi = new Remi()
remi.register(app, plugins, function(err) {
expect(err).to.not.exist

Expand All @@ -147,9 +144,8 @@ describe('Remi', function() {
corePlugins: [plugin],
})

let target = {}
return remi.register(target, [plugin])
.then(() => remi.register(target, [plugin]))
return remi.register(app, [plugin])
.then(() => remi.register(app, [plugin]))
.then(() => expect(plugin).to.have.been.calledOnce)
})

Expand All @@ -160,10 +156,9 @@ describe('Remi', function() {
corePlugins: [plugin],
})

let target = {}
return remi
.register(target, [plugin])
.then(() => remi.register(target, [plugin]))
.register(app, [plugin])
.then(() => remi.register(app, [plugin]))
.then(() => expect(plugin).to.have.been.calledOnce)
})

Expand All @@ -178,13 +173,10 @@ describe('Remi', function() {
dependencies: ['plugin1'],
})

let remi = new Remi({})

let target = {}
remi.register(target, [plugin1], function(err) {
remi.register(app, [plugin1], function(err) {
expect(err).to.not.exist

remi.register(target, [plugin2], function(err) {
remi.register(app, [plugin2], function(err) {
expect(err).to.not.exist
done()
})
Expand Down

0 comments on commit a15f7db

Please sign in to comment.