wardbell / bardjs

Spec helpers for testing angular v.1.x apps with Mocha, Jasmine and QUnit
MIT License
178 stars 34 forks source link

MockService Doesn't Work with Services Defined as an ES6 Class #50

Open jongunter opened 7 years ago

jongunter commented 7 years ago

This fails (apologies for the whitespace issues)

 class MyService {

        doAThing(){
            return 'bad';
        }

    }

////

        bard.appModule('app');

        bard.inject(this, 'MyService');
        bard.mockService(MyService, {
            _default: false
        });

    it('returns the proper values', ()=> {
        expect(MyService.doAThing()).toBe(false);
    })

Meanwhile, this succeeds:

  function MyService() {
        var returnBad = function () {
            return 'bad';
        };
        this.doAThing = returnBad;
    }

////

        bard.appModule('app');

        bard.inject(this, 'MyService');
        bard.mockService(MyService, {
            _default: false
        });

    it('returns the proper values', ()=> {
        expect(MyService.doAThing()).toBe(false);
    })