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.

Testing with jest

See original GitHub issue

I’m writing some test for my component using jest, and i came across an issue that says Jest encountered an unexpected token and it’s pointing to my moti import.

Im not sure how to fix this. please help.

Screen Shot 2022-03-10 at 10 58 44 PM

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rviecelicommented, Mar 16, 2022

I think you aren’t testing the animation, then you need to mock it creating __mocks__/moti.ts with

import { View as MotiView } from 'react-native';
export { MotiView };

If you are using other components or hooks, you need to mock them as well.

0reactions
kvntzncommented, Dec 19, 2022

late to the party but here’s how I did it.

jest.mock('moti', () => {
    MotiView: () => 'MotiView';
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest · Delightful JavaScript Testing
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, ......
Read more >
Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >
Jest Tutorial - JavaScript Unit Testing Using Jest Framework
In this Jest tutorial, we will learn about various Jest features, Jest matchers and how to use Jest framework for JavaScript Unit Testing....
Read more >
Jest Testing Tutorial: 5 Easy Steps - Testim Blog
1. Install Jest Globally · 2. Create a Sample Project · 3. Add Jest to the Project · 4. Write Your First Test...
Read more >
What Is Jest – A Tutorial on How to Use Jest - LambdaTest
Jest is a JavaScript-based framework for testing React, React Native and other JavaScript-based applications. In many cases, unit tests don't provide accurate ...
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