Code Monkey home page Code Monkey logo

thingworx-jest's Introduction

Jest JavaScript Testing Framework for ThingWorx Services

Installation

  1. Create a generic thing and give it a name (e.g. JestFramework)
  2. Add a new service on the thing
  3. Give the service a name (e.g. importScript)
  4. Set the output of the service to STRING data type
  5. Copy the contents of jest.js and paste into the service script text editor
  6. Save the service
  7. Save the thing

Usage

After installation, you may reuse this script in any service on any thing/template/shape by including the following snippet at the beginning of the service:

/** import { expect, describe, test } */
eval(Things['JestFramework'].importScript())(this); // jshint ignore:line

Make sure to set the output of the service to INFOTABLE.

Note: I typically create a separate service on each of my things/templates/shapes called __UNIT_TESTS__ThingName which runs all of the unit tests for the entity's services.

Add your unit tests after the snippet:

describe('Echo service', function() {
  test('Normal input', function() {
    var input = { a: 1 };
    expect(me.EchoService(input)).toEqual(input);
  });
});

Then execute the service. The result is an infotable with unit test results.

How This Works

ThingWorx does not allow passing functions as arguments to services so all javascript functions need to be defined inside of the service. To emulate exporting a script, the entire framework is placed inside of a function and Function.prototype.toString() is utillized to get the source code for the function. To emulate importing a script, eval() is utilized to evaluate the source code returned inside of the calling service. The export of the script source code could be avoided by placing the source string directly in a property and then imported by getting the value of the property instead of calling the service.

Todo

  • toContain

thingworx-jest's People

Contributors

jmmoser avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vxba

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.