test: react

This commit is contained in:
cha0s 2024-02-15 04:58:13 -06:00
parent 1b13374b10
commit b205bcc18b
8 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import {expect} from 'chai';
import {withWeb} from '@flecks/headless/test/helpers/with-web';
it('implements react providers', withWeb(
async ({page, response}) => {
expect(response)
.to.not.be.null;
expect(response.ok())
.to.be.true;
const output = await page.waitForSelector('.provider-test');
expect(await output?.evaluate((el) => el.textContent))
.to.equal('foobar');
},
{template: 'templates/provider'},
));

View File

@ -0,0 +1,21 @@
import {expect} from 'chai';
import {withWeb} from '@flecks/headless/test/helpers/with-web';
it('does ssr', withWeb(
async ({page, response}) => {
expect(response)
.to.not.be.null;
expect(response.ok())
.to.be.true;
const output = await page.waitForSelector('.provider-test');
expect(await output?.evaluate((el) => el.textContent))
.to.equal('foobar');
},
{
beforePage: async ({page}) => {
await page.setJavaScriptEnabled(false);
},
template: 'templates/provider',
},
));

View File

@ -0,0 +1,4 @@
'@flecks/core': {}
'@flecks/server': {}
'@flecks/react': {}
'test:./test': {}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,3 @@
{
"dependencies": {"@flecks/react": "*"}
}

View File

@ -0,0 +1,3 @@
import {createContext} from '@flecks/react';
export const Context = createContext();

View File

@ -0,0 +1,7 @@
import {Context} from './context';
import {Component} from './root';
export const hooks = {
'@flecks/react.providers': () => [Context.Provider, {value: 'foobar'}],
'@flecks/react.roots': () => Component,
};

View File

@ -0,0 +1,8 @@
import {useContext, React} from '@flecks/react';
import {Context} from './context';
export function Component() {
const foobar = useContext(Context);
return <div className="provider-test">{foobar}</div>;
}