Coder Social home page Coder Social logo

fakeStateProvider about bardjs HOT 9 OPEN

wardbell avatar wardbell commented on May 22, 2024
fakeStateProvider

from bardjs.

Comments (9)

wardbell avatar wardbell commented on May 22, 2024

Hmmm. Not terribly obvious is it.

Right now it simply stubs out everything in order to disable routing without blowing up.

My thought was that, you would inject $state into your test (perhaps in a beforeEach) and then monkey-patch as you need.

Here's what I had in mind:

    beforeEach(function() {
        // get fake $state router service
        bard.inject(this, '$state');

        // plug in fake $state router values for this set of tests
        $state.current = {/* fake values here */};
        $state.state = {/* fake values here */};
    })

I confess I haven't actually tried it. Perhaps you will be the first and give me some feedback :-)

from bardjs.

wardbell avatar wardbell commented on May 22, 2024

I released v.0.1.5 with these comments.

from bardjs.

johnpapa avatar johnpapa commented on May 22, 2024

@zuzana does that answer your question?

from bardjs.

zuzana avatar zuzana commented on May 22, 2024

unfortunately not, the get function I would need to fake gets executed before I am able to inject because it is part of module.run.

I went around it like this:

beforeEach(function() {
    module('myApp.home', function($stateProvider){
        $stateProvider.$get = function() {
            return {
                get: sinon.stub()
            };
        };
    });
    bard.inject(this, '$controller', '$rootScope');
});

It might be useful to change the concatenation order in following code:

function appModule() {
    var args = Array.prototype.slice.call(arguments, 0);
    args = args.concat(fakeRouteHelperProvider, fakeRouteProvider,
                       fakeStateProvider, fakeToastr);
    return angular.mock.module.apply(angular.mock, args);
}

to

function appModule() {
    var args = Array.prototype.slice.call(arguments, 0);
    args = [fakeRouteHelperProvider, fakeRouteProvider,
                       fakeStateProvider, fakeToastr].concat(args);
    return angular.mock.module.apply(angular.mock, args);
}

so that way, if fakeStateProvider is not enough, I can override it with my own that has mocked properties I need.

bard.appModule('myApp.home', myFakeStateProvider);

But then again, appModule is meant to save lines, and since I'm adding to it my own fakers, then I better just use module.

from bardjs.

wardbell avatar wardbell commented on May 22, 2024

Chalk up another example of why I avoid module.run! It never gives you a chance to fake the run handler.

If I do need run, I make sure that anything substantive calls an injected service. Then I can fake that service and control its behavior and the run behavior indirectly.

Perhaps "avoid run" is a tip for the style guide.

FWIW, your approach of faking the stateProvider on your own is what I would do. The bard version wont help you and I don't think I can improve the bard version without making it more complex.

from bardjs.

zuzana avatar zuzana commented on May 22, 2024

ok, thanks for your responses, going to close this.

from bardjs.

johnpapa avatar johnpapa commented on May 22, 2024

cc // @chintan-patel @johnpapa

from bardjs.

gaelollivier avatar gaelollivier commented on May 22, 2024

Why not changing the order of concatenation as @zuzana suggested ? That would allow to still use the faked services while being able to override them ?

from bardjs.

johnpapa avatar johnpapa commented on May 22, 2024

I've avoided using bard.appModule for this reason. Wondering if we should just remove it @wardbell

from bardjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.