question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to unit test models, views and routes?

See original GitHub issue

Dusting off #216 I wondered if there was any progress on it but also how are people going about testing their models, views and routes? Some documented guides would be nice and actually the Yeoman Generator should scaffold tests with the appropriate keystone helpers.

I am especially interesting in testing the models and views.

Have any of you written any keystone-helpers for testing?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ericelliottcommented, Jan 13, 2016

Here’s how I’m testing routes in the universal-keystone-boilerplate:

import test from 'tape';
import request from 'supertest';
import keystone from 'test/helpers/keystone';

const app = keystone.app;
const route = '/';

test(`GET ${ route }`, assert => {
  assert.test(route, assert => {
    const msg = 'should not return an error';

    request(app)
      .get(route)
      .expect(200)
      .end(err => {
        assert.error(err, msg);
        assert.end();
      });
  });
});

From there, it’s easy to run assertions against the response body. We should also add cross-browser testing with something like Sauce Labs, but some minimal route testing is a good first step.

0reactions
mxstbrcommented, Apr 29, 2016

@webteckie has done a ton of work on this, so I’ll close this for now as we don’t need the issue to remind us to do it. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Routes and Controllers | The Odin Project
Unit Testing is important for many reasons that we probably don't need to cover right now. ... Use the supertest module to test...
Read more >
Unit Testing Routes
It tests that the route exists in the route table as you intended AND it confirms that a Controller and Action method exist...
Read more >
Testing Routes - Ember Guides
Testing routes can be done both via integration or unit tests. Integration tests will likely provide better coverage for routes because routes are...
Read more >
21 - Unit Testing Routing | Angular | Karma | Jasmine - YouTube
Angular unit testing for Routing is a interesting topic and RouterTestingModule is used for unit testing the routes.
Read more >
EP 13.13 - Angular / Unit Testing / Routing - YouTube
EP 13.13 - Angular / Unit Testing / Routing ... 24K views 3 years ago ... We can test routing in Angular by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found