Skip to content

Commit

Permalink
Handle non-function topics; closes #396
Browse files Browse the repository at this point in the history
  • Loading branch information
evanp committed May 7, 2018
1 parent 35ab1fd commit 644b5b6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/batch.js
Expand Up @@ -46,10 +46,15 @@ class Batch {
`keys of definition must be strings, not '${name}'`)

if (name === 'topic') {
assert.ok(!_.isNil(value), `topic must be defined and not null`)
debug(`Adding topic to '${this.title}'`)
assert.isFunction(value,
`'topic' of '${this.title}' must be a function`)
this.topic = value
if (_.isFunction(value)) {
this.topic = value
} else {
this.topic = () => {
return value
}
}
} else if (name === 'teardown') {
debug(`Adding teardown to '${this.title}'`)
assert.isFunction(value,
Expand Down
33 changes: 33 additions & 0 deletions test/test-static-topic.js
@@ -0,0 +1,33 @@
// test-static-topic.js -- A topic that is not a function
//
// Copyright 2018 Fuzzy.ai <evan@fuzzy.ai>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict'

const vows = require('../lib/index')
const assert = vows.assert

vows.describe('topic that is not a function')
.addBatch({
'When we use a static topic': {
topic: 42,
'it works' (err, data) {
assert.ifError(err)
assert.isNumber(data)
assert.equal(data, 42)
}
}
})
.export(module)

0 comments on commit 644b5b6

Please sign in to comment.