Comments (4)
How are you trying to execute it?
from ospec.
How are you trying to execute it?
node version: v15.3.0
** My components are written in JSX **
I'm doing npm test.
package.json
...
...
"scripts": {
"test": "ospec --preload --experimental-modules ./test-setup.js"
},
...
...
test-setup.js
import {default as o} from 'ospec'
import {default as jsdom} from 'jsdom'
var dom = new jsdom.JSDOM("", {
// So we can get `requestAnimationFrame`
pretendToBeVisual: true,
})
// Fill in the globals Mithril needs to operate. Also, the first two are often
// useful to have just in tests.
global.window = require("mithril/test-utils/browserMock.js")(); //dom.window
global.document = dom.window.document
global.requestAnimationFrame = dom.window.requestAnimationFrame
import m from 'mithril'
global.window.m = m
// And now, make sure JSDOM ends when the tests end.
o.after(function() {
dom.window.close()
})
alerts.js
import SVGIcon from './svgs';
/**
* Alerts of all types
*/
const Alert = () => {
return {
view(vnode) {
return (
<div
class={`alert alert-${vnode.attrs.type} clearfix fade show d-flex justify-content-between`}
>
<div class="flex-fill">{vnode.children}</div>
</div>
);
},
};
};
const ClosableError = () => {
return {
view(vnode) {
return vnode.attrs.visibe ? (
<div class="alert alert-danger show-this clearfix show d-flex justify-content-between text-wrap my-2">
<span class="align-self-center flex-fill">{vnode.attrs.text}</span>
<div class="s-action-close-alert mt-n1 ml-auto">
<button
title="Close"
onclick={() => {
!vnode.attrs.close_func();
}}
class="round-btn-xs bg-transparent"
data-dismiss="alert"
aria-label="Close"
>
<SVGIcon name="Close" class="s-svg-sm fill-secondary"></SVGIcon>
</button>
</div>
</div>
) : null;
},
};
};
export { Alert, ClosableError };
from ospec.
@mchampaneri Sorry for the delay, the project was moribund.
Is this still relevant?
from ospec.
@mchampaneri You can either turn your tests into modules:
// with {"type":"module"} in tests/package.json
import o from "ospec"
// I didn't test this beyond verifying it doesn't crash on import
import mq from "mithril-query"
import { Alert } from "[path]";
o.spec("Alert", function() {
o("Alert", function() {
var out = mq(Alert, { type: "danger" }, ["You got it"]);
out.should.have("alert-danger");
out.should.contain("You got it");
});
});
o.run();
or use a dynamic import()
in a o.before()
hook:
var mq = require("mithril-query");
var o = require("ospec");
o.spec("Alert", function() {
let Alert
o.before(async() {
Alert = await import('[path]')
})
o("Alert", function() {
var out = mq(Alert, { type: "danger" }, ["You got it"]);
out.should.have("alert-danger");
out.should.contain("You got it");
});
});
o.run();
from ospec.
Related Issues (20)
- ERR_UNSUPPORTED_ESM_URL_SCHEME error on Windows 10 HOT 4
- deepEquals can't handle objects with a null prototype
- The report should show the own properties of errors that were caught in tests
- Assertion descriptions don't interpolate when used with tagged template literal syntax
- `.satisfies()` is too verbose, `.notSatisfies()` and `.notDeepEquals()` are of little use
- Complex assetions like `deepEquals` and `satisfies` plugins should differentiate between bail outs and internal errors
- Logging: bailout should be reported apart from standard failures
- Lost assertions in async tests HOT 1
- Immutable woes? HOT 1
- Adapt the `lock()` mechanism as a core part of o.spy()
- re-think the results output
- Context and running streaks in parallel.
- Failed assertion reporting does unnecessary string substitution HOT 2
- spy.calls doesn't seem to match TypeScript definitions
- `o.before()` within a `o.spec` still runs even when no tests are running HOT 4
- Question: View realtime test progress?
- deepEquals assertions ignore symbol properties.
- DeepEquals should handle Sets (and Maps) HOT 1
- Native TS support would be nice to have HOT 2
- [Feature] The reporter ignores error causes (and possibly aggregate errors too) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ospec.