diff --git a/test/helper/index.js b/test/helper/index.js index 8a0ab180..f8d39287 100644 --- a/test/helper/index.js +++ b/test/helper/index.js @@ -226,7 +226,7 @@ export function inject(fn) { ); } - BPMN_JS.invoke(fn); + return BPMN_JS.invoke(fn); }; } diff --git a/test/spec/helper/InjectSpec.js b/test/spec/helper/InjectSpec.js new file mode 100644 index 00000000..a3b4a4ef --- /dev/null +++ b/test/spec/helper/InjectSpec.js @@ -0,0 +1,66 @@ +import { + bootstrapModeler, + inject +} from 'test/TestHelper'; + +import coreModule from 'lib/core'; +import { expect } from 'chai'; + + +describe('helper - inject', function() { + + var diagramXML = require('../../fixtures/bpmn/simple.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: [ + coreModule + ] + })); + + + it('should work with Promise as return value', function() { + + // given + var expected = 'resolved'; + + // when + var test = inject(function(eventBus) { + + expect(eventBus).to.exist; + + return Promise.resolve(expected); + }); + + // then + return test().then(function(result) { + + expect(result).to.eql(expected); + }); + }); + + + it('should handle Promise rejection', function() { + + // given + var expected = new Error('rejected'); + + function onResolved() { + throw new Error('should not resolve'); + } + + function onRejected(error) { + expect(error).to.eql(expected); + } + + // when + var test = inject(function(eventBus) { + expect(eventBus).to.exist; + + return Promise.reject(expected); + }); + + // then + return test().then(onResolved, onRejected); + }); + +});