Giter VIP home page Giter VIP logo

Comments (4)

dead-claudia avatar dead-claudia commented on May 31, 2024

How are you trying to execute it?

from ospec.

mchampaneri avatar mchampaneri commented on May 31, 2024

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.

pygy avatar pygy commented on May 31, 2024

@mchampaneri Sorry for the delay, the project was moribund.

Is this still relevant?

from ospec.

pygy avatar pygy commented on May 31, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.