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

Write unit tests for existing classes #94

Open
kwokwilliam opened this issue Jul 26, 2018 · 6 comments
Open

Write unit tests for existing classes #94

kwokwilliam opened this issue Jul 26, 2018 · 6 comments
Assignees
Labels
enhancement an improvement to a pre-existing feature or component (that is not a bug fix) low priority a "nice to have" improvement. This task is not critical or time-sensitive. prod a task that we would only need to have for deployment to production (e.g. an optimization)

Comments

@kwokwilliam
Copy link
Contributor

I have been looking into writing unit tests for React components.

It's done using a library called Enzyme, created by Airbnb (http://airbnb.io/enzyme/).

I'll start writing a few tests. I've never really wrote any unit tests before, so this'll be new. I'm sure it'll be very useful in the future for expansion.

@kwokwilliam kwokwilliam self-assigned this Jul 26, 2018
@kwokwilliam kwokwilliam added enhancement an improvement to a pre-existing feature or component (that is not a bug fix) prod a task that we would only need to have for deployment to production (e.g. an optimization) labels Jul 26, 2018
@kwokwilliam
Copy link
Contributor Author

Depending on the code, I may modify implementations to use dependency injections, so we can mock dependencies using jest.

@kwokwilliam
Copy link
Contributor Author

Very seamless to use. This is the code for one test, and it's very straightforward to use. getOrderedConcepts() is a function in wrapper which is defined as a shallow(<WorldView />).

  test('getOrderedConcepts contains only concepts in ConceptAbbreviations', () => {
    const concepts = wrapper.instance().getOrderedConcepts();
    concepts.forEach((concept) => {
      expect(g[concept.name] !== undefined).toBe(true);
    });
  });

@kwokwilliam
Copy link
Contributor Author

Added a CSS proxy because tests were crashing when trying to import objects with a CSS import at the top.

jestjs/jest#3094 (comment)

@kwokwilliam
Copy link
Contributor Author

Wrote guide a couple days ago for writing unit tests with Enzyme https://github.com/codeandcognition/koconut/blob/summer2018-master/docs/jest.md

@kwokwilliam
Copy link
Contributor Author

Fix existing unit tests with new router change

@kwokwilliam kwokwilliam changed the title Write unit tests Write unit tests for existing classes Sep 10, 2018
@bxie bxie added this to Backlog in Backlog Oct 22, 2018
@bxie bxie added this to Backlog in NCME Dev Oct 22, 2018
@bxie
Copy link
Collaborator

bxie commented Jun 6, 2019

test suite exists in src/tests, but they're out of date and incomplete

@bxie bxie added this to the nice to have milestone Jul 6, 2019
@bxie bxie added the low priority a "nice to have" improvement. This task is not critical or time-sensitive. label Jul 6, 2019
@bxie bxie removed this from the nice to have milestone Jul 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement an improvement to a pre-existing feature or component (that is not a bug fix) low priority a "nice to have" improvement. This task is not critical or time-sensitive. prod a task that we would only need to have for deployment to production (e.g. an optimization)
Projects
NCME Dev
  
Backlog
Backlog
Backlog
Development

No branches or pull requests

2 participants