practicalmeteor / meteor-mocha

Depreciated - Write meteor package tests with mocha and run them in the browser or from the command line with spacejam.
https://atmospherejs.com/practicalmeteor/mocha
Other
41 stars 13 forks source link

Angular Meteor testing, before vs beforeEach #65

Open huttarichard opened 8 years ago

huttarichard commented 8 years ago

Hi there, great job, I don't know if this is more issue of angular mocks or meteor-mocha by I try to ask here:

Not working example:

     describe("Some service", function(){
        let $log;

        before(window.module('module'));

        before(inject(function(_$log_) {
            $log = _$log_;
        }))

        it("service $log should be injected already", function() {
            console.log($log); // this never will be executed
        })
    })

you got an error

TypeError: Cannot read property '$injector' of null
    at Context.workFn (packages/modules.js?hash=d4a34f37940fc21197870c59ffd5f42c062268c7:7409:22)
    at callFn (packages/practicalmeteor_mocha-core.js?hash=12c98471b374d75331cd9dcc7e691e23967c4550:4345:21)
    at Hook.Runnable.run (packages/practicalmeteor_mocha-core.js?hash=12c98471b374d75331cd9dcc7e691e23967c4550:4338:7)
    at next (packages/practicalmeteor_mocha-core.js?hash=12c98471b374d75331cd9dcc7e691e23967c4550:4684:10)
    at packages/practicalmeteor_mocha-core.js?hash=12c98471b374d75331cd9dcc7e691e23967c4550:4706:5
    at timeslice (packages/practicalmeteor_mocha-core.js?hash=12c98471b374d75331cd9dcc7e691e23967c4550:12674:27)

however if you change before to before each it will work properly

Working example:

     describe("Some service", function(){
        let $log;

        beforeEach(window.module('module'));

        beforeEach(inject(function(_$log_) {
            $log = _$log_;
        }))

        it("service $log should be injected already", function() {
            console.log($log); // you got an $log service
        })
    })

What is this all about, is it just my misunderstanding of angular-mocks libary or is this bug within meteor-mocha package?

huttarichard commented 8 years ago

I also tried something like this:

before(function() {
  window.module('some.module');
  inject(function(_$log_) {
    console.log(_$log_) // never executed
  })
})

this example not execute inject function, instead return workFn which you must execute by yourself in correct context, otherwise give you something like cannot read property '$modules' of null. Same problem same place, if you change before for beforeEach it will run properly