How to use Laika test Meteor router or Iron router

I am using laika for testing and meteor-router packaging for wiring. I want to do some tests to navigate to a certain page, fill out a form, submit it and check the success message, but I still stick to the navigation part. This is my first attempt:

var assert = require('assert');

suite('Router', function() {
test('navigate', function(done, server, client) {
client.eval(function() {
Meteor.Router.to ('test');
var title = $('h1').text();
emit('title', title);
})
.once( 'title', function(title) {
assert.equal(title,'Test');
done();
});
});
});

This doesn’t work because Meteor.Router.to has no callback, and I don’t know how to execute the next line when a new page is loaded.

I also tried this Things

var page = require('webpage').create();

page.open('http://localhost:3000/ test', function () {
...
}

But I get an error error: The module’webpage’ cannot be found

Edit

I want to go to iron router, so any answers will be helpful.

me Had the same problem. Before running the test, I need to navigate to a certain page. I am also using iron router. I think you can’t just execute Router.go(‘foo’) , That’s it. You need to wait until the actual routing occurs. Fortunately the router exposes a method Router.current(), which is a passive data source that will change once your page is ready. Therefore, in order to navigate before running the test To get to a specific route, I first run the following code block:

// route to /some/path
client.evalSync(function() {
// react on route change
Deps.autorun(function() {
if (Router.current().path =='/some/path') {
emit(' return');
this.stop();
}
});
Router.go('/some/path');
});< /pre>

Since this is in evalSync(), everything after this block will be executed after the routing is complete. Hope this helps.

I I am using laika for testing and meteor-router encapsulation for wiring. I want to do some tests to navigate to a certain page, fill out a form, submit it and check the success message, but I still stick to the navigation part. This is my number one Attempts:

var assert = require('assert');

suite('Router', function() {
test('navigate', function(done, server, client) {
client.eval(function() {
Meteor.Router.to('test');
var title = $('h1').text();
emit('title', title);
})
.once('title', function(title) {
assert.equal(title, 'Test');
done();
});
});
});

This does not work because Meteor.Router .to has no callback, and I don’t know how to execute the next line when loading a new page.

I also tried something like this

var page = require ('webpage').create();

page.open('http://localhost:3000/test', function () {
...
}

But I get the error error: Cannot find module'webpage'

Edit

I want to go to iron router, so any answers will be helpful.

I have the same problem. Before running the test, I need to navigate to a certain page. I am also using iron router. I think you can’t just execute Router.go('foo'), that's it. You need to wait until the actual routing occurs. Fortunately the router exposes a method Router.current(), which is a passive data source that will change once your page is ready. Therefore, in order to navigate to a specific route before running the test, I first run the following code block:

// route to /some/path
client. evalSync(function() {
// react on route change
Deps.autorun(function() {
if (Router.current().path =='/some/path') {
emit('return');
this.stop();
}
});
Router.go('/some/path');
});

Since this is in evalSync(), everything after this block will be executed after routing is complete. Hope this helps.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1340 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.