Neutron Polarization Manipulator

    @fattafatta/rescript-zora-jsdom

    0.1.1 • Public • Published

    rescript-zora-jsdom: A jsdom wrapper for zora tests

    This package provides a simple ReScript binding for the jsdom module to use with zora tests. It works as extension to rescript-zora and provides a (minimal) DOM environment (e.g. a document and a window object) for all wrapped tests.

    It was specifically designed to test react hooks with rescript-hooks-testing-library and zora.

    Disclaimer

    I'm very new to ReScript (and functional programming in general). So there is probably a lot of room for improvements in this package. Any tips or suggestions are very welcome.

    Installation

    Install with npm:

    npm install --save-dev @fattafatta/rescript-zora-jsdom

    Or install with yarn:

    yarn add --dev @fattafatta/rescript-zora-jsdom

    Add @fattafatta/rescript-zora-jsdom as a (dev-)dependency to your bsconfig.json:

    "bs-dev-dependencies": ["@dusty-phillips/rescript-zora", "@fattafatta/rescript-zora-jsdom"]

    Note

    This package requires @dusty-phillips/rescript-zora as a peer dependency.

    Usage

    Run blocking tests

    Simply use zoraWithDOMBlock instead of zoraBlock. All tests will use the same DOM environment.

    ZoraJsdom.zoraWithDOMBlock("run tests sequentially", t => {
      open Zora
      t->block("test 1", t => {
        t->ok(document, "should have a document")
      })
      t->block("test 2", t => {
        t->ok(document, "should have a document too")
      })
    })

    Run parallel tests

    Use zoraWithDOM instead of zora to run tests in parallel. All tests will share the same DOM environment.

    ZoraJsdom.zoraWithDOM("run tests in parallel", t => {
      open Zora
      t->test("test 1", t => {
        t->ok(document, "should have a document")
        done()
      })
      t->test("test 2", t => {
        t->ok(document, "should have a document too")
        done()
      })
      done()
    })

    Run tests in seperate DOM environments

    You can use testWithDOM or blockWithDOM to run multiple tests in different DOM environments.

    // Run tests in parallel
    open Zora
    zora("run tests in parallel", t => {
      t->ZoraJsdom.testWithDOM("test 1", t => {
        t->ok(document, "should have a document")
        done()
      })
      t->ZoraJsdom.testWithDOM("test 2", t => {
        t->ok(document, "should have a document too")
        done()
      })
      done()
    })
    
    // Run tests sequentially
    open Zora
    zoraBlock("run tests sequentially", t => {
      t->ZoraJsdom.blockWithDOM("test 1", t => {
        t->ok(document, "should have a document")
      })
      t->ZoraJsdom.blockWithDOM("test 2", t => {
        t->ok(document, "should have a document too")
      })
    })

    Install

    npm i @fattafatta/rescript-zora-jsdom

    DownloadsWeekly Downloads

    4

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    99.5 kB

    Total Files

    13

    Last publish

    Collaborators

    • fattafatta