Last active
May 28, 2019 18:48
-
-
Save alexxxmf/258e7893c08a9fffee8d15efcebabd38 to your computer and use it in GitHub Desktop.
RecipeListScreen.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { mount, shallow } from 'enzyme'; | |
import { View, TextInput, Image, Text } from 'react-native'; | |
import toJSON from 'enzyme-to-json'; | |
import { MockedProvider } from 'react-apollo/test-utils'; | |
import renderer from 'react-test-renderer'; | |
import wait from 'waait'; | |
import { GET_RECIPIES_QUERY } from '../src/graphql/queries'; | |
import RecipeListScreen, {RecipeListScreenWithoutHocs} from '../src/screens/RecipeListScreen'; | |
import console = require('console'); | |
fakeRecipeList = () => { | |
return [ | |
{ | |
"recipeId": 2, | |
"recipeName": "Keto mexican scrambled eggs", | |
"description": "Spice up your breakfast with this flavorful keto egg dish. Jalapenos, tomatoes, and scallions enhance the scrambled eggs with just the right amount of zing. Guaranteed to liven up your day!", | |
"carbs": 2, | |
"preparationTimeMin": 300, | |
"preparationTimeMax": 600, | |
"difficulty": 2, | |
"mainImageEntry": "ketoMexicanEggs", | |
"foodType": "breakfast" | |
}, | |
{ | |
"recipeId": 3, | |
"recipeName": "Classic bacon and eggs", | |
"description": "One of the all-time best keto breakfasts ever! Step up your bacon and eggs game with this mouth-watering version. Gauge your hunger meter and enjoy as many eggs as you need to feel satisfied. We’re drooling just thinking about this dish of keto deliciousness!", | |
"carbs": 1, | |
"preparationTimeMin": 450, | |
"preparationTimeMax": 600, | |
"difficulty": 2, | |
"mainImageEntry": "classicBaconAndEggs", | |
"foodType": "breakfast" | |
} | |
] | |
} | |
jest.mock("react-navigation", () => { | |
return { | |
withNavigation: (component) => component | |
} | |
}); | |
jest.mock("react-redux", () => { | |
return { | |
connect: (component) => component, | |
Provider: (component) => component | |
} | |
}); | |
const mocks = [ | |
{ | |
request: { | |
query: GET_RECIPIES_QUERY | |
}, | |
result: { | |
data: { | |
getRecipes: fakeRecipeList(), | |
}, | |
}, | |
}, | |
]; | |
it('renders correctly', async () => {; | |
const screen = renderer.create( | |
<MockedProvider mocks={mocks} addTypename={false}> | |
<RecipeListScreenWithoutHocs searchFilter="asdad"/> | |
</MockedProvider> | |
) | |
console.log(screen) | |
expect(screen.root.findByType(Text).props.children).toBe('Loading...') | |
await wait(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment