Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module configuration is not passed to the mocked module #8

Open
tatablack opened this issue Aug 8, 2013 · 0 comments
Open

Module configuration is not passed to the mocked module #8

tatablack opened this issue Aug 8, 2013 · 0 comments

Comments

@tatablack
Copy link

I have a problem and two possible solutions, though I didn't peruse your code enough to determine which one is better..

I need to set a specific configuration for the module under test, like this:

describe('My component', function() {
    beforeEach(function() {
        requirejs.config({
            config: {
                'src/MyComponent': {
                    someVariable: true
                }
            }
        });
    });

    it('should be able to read its own configuration', function(done) {
        require(['isolate!src/MyComponent'], function(MyComponent) {
            var comp = new MyComponent();
            comp.getSomeVariable().should.be.true;
            done();
        });
    });
});

Now, if the getSomeVariable method inside MyComponent needs to read from the module's configuration (using module().config) it would fail, since that configuration is not passed when the module is required through Isolate.

The solution seems to be simple: when setting the config here at line 178, the actual configuration of the module should be set too:

isolatedRequire = IsolationContext._require.config
        context: isolatedContextName
        baseUrl: mainCtx.config.baseUrl
        config: ACTUALCONFIGURATIONHERE

What I'm not sure is whether we should pass mainCtx.config, or config.config. In my own test they seemed to contain pretty much the same data, which is why I'm not just opening a pull request... 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant