This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #66
- Loading branch information
Showing
10 changed files
with
244 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "reactn", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"author": "Charles Stover <[email protected]>", | ||
"description": "React, but with built-in global state management.", | ||
"homepage": "https://github.com/CharlesStover/reactn#readme", | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as React from 'react'; | ||
import { render } from 'react-testing-library'; | ||
import ReactN = require('../src/index'); | ||
import ReactNProvider from '../types/provider'; | ||
import { Getter } from '../types/with-global'; | ||
import { G, INITIAL_STATE } from './utils/initial'; | ||
|
||
|
||
|
||
// TS2339: Property 'innerHTML' does not exist on type 'HTMLSpanElement'. | ||
interface Container extends HTMLSpanElement { | ||
innerHTML: string; | ||
} | ||
|
||
interface Props { | ||
z: string; | ||
} | ||
|
||
|
||
|
||
const INNER_HTML: string = `<span>${INITIAL_STATE.z}</span>`; | ||
|
||
const mapGlobalToProps: Getter<G, {}, {}, Props> = ({ z }: G): Props => ({ z }); | ||
|
||
const TestComponent = ({ z }: Props): JSX.Element => { | ||
return <span>{z}</span>; | ||
}; | ||
|
||
|
||
|
||
describe('withGlobal', (): void => { | ||
|
||
afterEach((): void => { | ||
ReactN.resetGlobal(); | ||
}); | ||
|
||
it('should support default global state', async (): Promise<void> => { | ||
await ReactN.setGlobal(INITIAL_STATE); | ||
const TestComponentHoc: React.ComponentClass<{}> = | ||
ReactN.withGlobal(mapGlobalToProps)(TestComponent); | ||
|
||
const testComponent = render(<TestComponentHoc />); | ||
|
||
const span: Container = testComponent.container as Container; | ||
expect(span.innerHTML).toBe(INNER_HTML); | ||
}); | ||
|
||
describe('Provider', (): void => { | ||
|
||
let Provider: ReactNProvider<G>; | ||
beforeEach((): void => { | ||
Provider = ReactN.createProvider(INITIAL_STATE); | ||
}); | ||
|
||
it('should support Context', (): void => { | ||
const TestComponentHoc: React.ComponentClass<{}> = | ||
ReactN.withGlobal(mapGlobalToProps)(TestComponent); | ||
|
||
const testComponent = render( | ||
<Provider> | ||
<TestComponentHoc /> | ||
</Provider>, | ||
); | ||
|
||
const span: Container = testComponent.container as Container; | ||
expect(span.innerHTML).toBe(INNER_HTML); | ||
}); | ||
|
||
it('should support Provider', (): void => { | ||
const TestComponentHoc: React.ComponentClass<{}> = | ||
Provider.withGlobal(mapGlobalToProps)(TestComponent); | ||
|
||
const testComponent = render(<TestComponentHoc />); | ||
|
||
const span: Container = testComponent.container as Container; | ||
expect(span.innerHTML).toBe(INNER_HTML); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.