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
| it("should count increase 1 when invoke increment func", async function () { | |
| jest.isolateModules(() => { | |
| let currentCount = 0; | |
| mockContext(currentCount); | |
| const Container = require("../../component/Counter/CounterContainer").default; | |
| const MockComponent = Container(() => <></>); | |
| let testRenderer = TestRenderer.create(<MockComponent/>); | |
| testRenderer.toTree().rendered.props.increment(); |
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
| let mockReducer; | |
| let mockState; | |
| function mockContext(count) { | |
| jest.doMock("../../context/CounterContext", () => { | |
| mockReducer = (action) => { | |
| mockState = counterReducer(mockState, action); | |
| }; | |
| mockState = { |
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 CounterContainer from "./CounterContainer"; | |
| export const Counter = CounterContainer(props => { | |
| return( | |
| <div className="wrapper"> | |
| <div className="btn-group"> | |
| <button onClick={props.increment}>increment</button> | |
| <button onClick={props.decrement}>decrement</button> | |
| </div> |
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, {useContext} from "react"; | |
| import {CounterContext} from "../../context/CounterContext"; | |
| export default Component => props => { | |
| const {counterState, counterDispatch} = useContext(CounterContext); | |
| const increment = () => { | |
| counterDispatch({type:"increment"}); | |
| } |
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
| export const counterReducer = (state, action) => { | |
| switch (action.type) { | |
| case 'increment': | |
| return { | |
| ...state, | |
| count: state.count + 1 | |
| }; | |
| case 'decrement': | |
| return { | |
| ...state, |
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, {useContext, useReducer} from "react"; | |
| import {Counter} from "./component/Counter/Counter"; | |
| import "./App.css"; | |
| import {CounterContext} from "./context/CounterContext"; | |
| import {counterReducer} from "./reducer/counterReducer"; | |
| function App() { | |
| const defaultState = useContext(CounterContext); | |
| const [counterState, counterDispatch] = useReducer(counterReducer, defaultState); | |
| return ( |
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'; | |
| export const CounterContext = React.createContext({ | |
| count: 0 | |
| }); |
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
| (function () { | |
| var currentWindow, | |
| // create an iframe and append to body to load a clean window object | |
| iframe = document.createElement('iframe'); | |
| iframe.style.display = 'none'; | |
| document.body.appendChild(iframe); | |
| // get the current list of properties on window | |
| currentWindow = Object.getOwnPropertyNames(window); | |
| // filter the list against the properties that exist in the clean window | |
| keys = currentWindow.filter(function(prop) { |
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
| console.log(a); | |
| sayHi(); | |
| var sayHi = function() { | |
| var name = 'Eric'; | |
| console.log('Hi ' + name); | |
| } | |
| var a = 'I"m a'; |
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
| console.log(a); | |
| sayHi(); | |
| function sayHi() { | |
| var name = 'Eric'; | |
| console.log('Hi ' + name); | |
| } | |
| var a = 'I"m a'; |
NewerOlder