-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from blitz-js/exclude-props
exclude-props
- Loading branch information
Showing
15 changed files
with
144 additions
and
36 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
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,4 +1,11 @@ | ||
{ | ||
"presets": ["next/babel"], | ||
"plugins": ["superjson-next"] | ||
} | ||
"presets": ["next/babel"], | ||
"plugins": [ | ||
[ | ||
"superjson-next", | ||
{ | ||
"exclude": ["superJsonSkipped"] | ||
} | ||
] | ||
] | ||
} |
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,19 @@ | ||
import type { InferGetStaticPropsType } from 'next'; | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: { | ||
superJsonSkipped: new Date(0).toISOString(), | ||
date: new Date(0) | ||
}, | ||
}; | ||
} | ||
|
||
const Page = (props: InferGetStaticPropsType<typeof getStaticProps>) => { | ||
return ( | ||
'props.superJsonSkipped is string: ' + | ||
(typeof props.superJsonSkipped === 'string') | ||
); | ||
}; | ||
|
||
export default Page; |
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,10 @@ | ||
import { Selector } from 'testcafe'; | ||
|
||
fixture`Excluded Props`.page`http://localhost:3099/excluded-props`; | ||
|
||
test('works', async (t) => { | ||
const result = Selector('#__next'); | ||
await t | ||
.expect(result.innerText) | ||
.eql('props.superJsonSkipped is string: true'); | ||
}); |
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
13 changes: 8 additions & 5 deletions
13
test/pages/gSP arrow function with implicit return/output.js
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
import { withSuperJSONPage } from "../src/tools" | ||
import { render } from "@testing-library/react-native" | ||
import * as React from "react" | ||
import { withSuperJSONPage, withSuperJSONProps } from '../src/tools'; | ||
import { render } from '@testing-library/react-native'; | ||
import * as React from 'react'; | ||
|
||
describe("tools", () => { | ||
describe("a component wrapped withSuperJSONPage", () => { | ||
describe("when used from a test", () => { | ||
it("works", () => { | ||
describe('tools', () => { | ||
describe('a component wrapped withSuperJSONPage', () => { | ||
describe('when used from a test', () => { | ||
it('works', () => { | ||
function Greeter(props: { name: string }) { | ||
return ( | ||
<p> | ||
Greetings, {props.name}! | ||
</p> | ||
) | ||
return <p>Greetings, {props.name}!</p>; | ||
} | ||
|
||
const WrappedGreeter = withSuperJSONPage(Greeter) | ||
const WrappedGreeter = withSuperJSONPage(Greeter); | ||
|
||
const GreeterFromTest = WrappedGreeter as any as typeof Greeter | ||
const GreeterFromTest = (WrappedGreeter as any) as typeof Greeter; | ||
|
||
const result = render(<GreeterFromTest name="Earthling" />) | ||
const result = render(<GreeterFromTest name="Earthling" />); | ||
expect(result.toJSON().children).toEqual([ | ||
"Greetings, ", "Earthling", "!" | ||
]) | ||
}) | ||
}) | ||
}) | ||
}) | ||
'Greetings, ', | ||
'Earthling', | ||
'!', | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('withSuperJSONProps', () => { | ||
it('respects `exclude`', async () => { | ||
const aDate = new Date(); | ||
const bDate = new Date(); | ||
async function gSSP() { | ||
return { | ||
props: { | ||
a: aDate, | ||
b: bDate, | ||
}, | ||
}; | ||
} | ||
const wrappedGssp = withSuperJSONProps(gSSP, ['a']); | ||
|
||
const result = await wrappedGssp(null as any); | ||
expect(result).toEqual({ | ||
props: { | ||
a: aDate, | ||
b: bDate.toISOString(), | ||
_superjson: { | ||
values: { | ||
b: ['Date'], | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |