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

Test args is mutated. #14

Closed
ghost opened this issue Jan 3, 2017 · 5 comments
Closed

Test args is mutated. #14

ghost opened this issue Jan 3, 2017 · 5 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Jan 3, 2017

Hi,

Great library! However found a bit of an oddity. The data table passed to each unroll appears to be mutated (the title row is removed) which means it cannot be a constant stored somewhere.

Got round this by having a function that creates the constant but was stuck for 5 minutes wondering why my data looked strange. I might have missed this in the docs, but if not might be worth adding?

Thanks
Dan.

@lawrencec
Copy link
Owner

lawrencec commented Jan 3, 2017

Hi Dan,

Think I know what you mean but I'd like to make sure I fix it correctly the first time. Would you mind posting your failing example? Much appreciated!

Cheers,
Loz

@SarahJaine
Copy link

Great library! I think I'm having the same problem as what @hq-mobile was describing. Storing the data table of testArgs as a const and using it in multiple unroll methods does not work. In the example below, on the second unroll() myRoutes does not have table headers. The error is Error: title not expanded as incorrect args passed in.

const myRoutes = [
    ['route'],
    ['/hello'],
    ['/bonjour']
]

describe('renders', function() {
    unroll(
        'h1 at #route',
        function(done, testArgs) {
            request
                .get(testArgs.route)

                .expect(200, function(error, response) {
                    let $ = cheerio.load(response.text);

                    expect($('h1').length).to.equal(1);
                    done();
                });
        },
        myRoutes
    );
    unroll(
        'h2 at #route',
        function(done, testArgs) {
            request
                .get(testArgs.route)
                .expect(200, function(error, response) {
                    let $ = cheerio.load(response.text);

                    expect($('h2').length).to.equal(1);
                    done();
                });
        },
        myRoutes
    );
}

It looks like this is because you're using .shift() to pull out the keys. https://github.com/lawrencec/Unroll/blob/master/lib/unroll.js#L17. Maybe you could use slicing instead to create two seperate variables? Something like:

var unrolledKeys = unrolledValues.slice(0,1);
var unrolledItems = unrolledValues.slice(1);

and then use unrolledItems in place of unrolledValues throughout the code?

Best,
Sj

@lawrencec
Copy link
Owner

Hi @SarahJaine, thanks for the testcase. I'm hoping to take a have a bit of time to look at this over the next couple of days.

@lawrencec
Copy link
Owner

@SarahJaine I've pushed a fix and published 1.2.1.

@SarahJaine
Copy link

@lawrencec Thank you!!!

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

No branches or pull requests

2 participants