Using initializer in unit test?

I have a stdlib initializer. In this initializer, I re-open some of the Ember built-in classes and add some custom methods. For example, I added reverseEach to Ember.Enumerable and Array .

They work fine in the application, but in tests I get "reverseEach: undefined is not a function".

How can I indicate that the test should use an initializer?

I tried needs: [..., 'initializer:stdlib'] . He will not stumble upon this, but I still get the "undefined" error.

Here is a test example:

 `import { test, moduleForModel } from 'ember-qunit'` moduleForModel 'foo', 'foo', needs: [ 'model:bar' 'initializer:stdlib' ] test 'deleteLastNItems', -> model = @subject() model.set '', ['foo', 'bar', 'baz', 'quux'] model.deleteLastNItems 2 # This should not die with "reverseEach: undefined is not a function" deepEquals model.get('someProperty'), ['foo', 'bar'] 
+5
source share
1 answer

You can use ember g initializer stdlib , it will generate a code sample for you, including a test.

 import Ember from 'ember'; import { initialize } from '../../../initializers/stdlib'; import { module, test } from 'qunit'; var registry, application; module('Unit | Initializer | stdlib', { beforeEach: function() { Ember.run(function() { application = Ember.Application.create(); registry = application.registry; application.deferReadiness(); }); } }); // Replace this with your real tests. test('it works', function(assert) { initialize(registry, application); // you would normally confirm the results of the initializer here assert.ok(true); }); 

Refer: Embossed Drawings

-1
source

Source: https://habr.com/ru/post/1212002/


All Articles