# How to configure a correct test environment for a fuse project.

**URL:** <https://forums.fusetools.com/t/how-to-configure-a-correct-test-environment-for-a-fuse-project/1902>\
**Category:** How-to Discussions\
**Created:** [November 30, 2017, 9:43pm UTC](https://forums.fusetools.com/t/how-to-configure-a-correct-test-environment-for-a-fuse-project/1902 "2017-11-30T21:43:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![toto007](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@toto007](https://forums.fusetools.com/u/toto007)\
**Post date:** [November 30, 2017, 9:43pm UTC](https://forums.fusetools.com/t/how-to-configure-a-correct-test-environment-for-a-fuse-project/1902/1 "2017-11-30T21:43:28Z")

</div>

I am trying to figure out how to create my own test environment to test the JavaScript classes I use in my fuse project.  
I analyzed the environment offered by fuse but this environment does not seem to allow you to test asynchronous calls as `Promise`:  
[https://www.fusetools.com/docs/testing/testing](https://www.fusetools.com/docs/testing/testing)

So I thought I’d configure the test environment `Mocha`, `Chai` and `Chai-promised`.  
The difficulty I am having, however, is in being able to test methods that have dependencies with JavaScript methods offered by the fuse framework such as “Fetch”.  
In fact, in the example that I leave the test fails because the method `fetch` is not available when I invoke the tests with Mocha.

I would like to have suggestions and examples of test environments that you have integrated into your fuse projects.

Thank you  
Giuseppe

Mainview.ux

```auto
<App>

    <JavaScript>
        var Post= require('Post');
        var Observable = require("FuseJS/Observable");
        var title = Observable();
        Post.get(1).then(function(response){
          response.value=response.title;
        });
        module.exports={
            title:title
        }
    </JavaScript>
    <Text>{title}</Text>
</App>

```

Post.js

```auto
function get(id) {

    var status = 0;
    var response_ok = false;
    return fetch('http://jsonplaceholder.typicode.com/posts/' + id, {
        method: 'GET'
    }).then(function (response) {
        status = response.status; // Get the HTTP status code
        response_ok = response.ok; // Is response.status in the 200-range?
        return response.json(); // This returns a promise
    }).then(function (responseObject) {
        console.dir(responseObject);
        return responseObject;
    }).catch(function (err) {
        console.dir(err.message);
    });
}

module.exports = {
    get: get
}

```

Test for Module Post.js

```auto
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);

var expect = chai.expect;
var should = chai.should()

var Post= require ('../Post');

describe("Test the behavior of Post", function () {
    it('The post should have the Title property', function () {
        expect(Post.get(1)).to.eventually.have.property("title");
    });

})

```

Output failed mocha -\> Test.js

```auto
mocha 

  Test the behavior of Post
call method
    1) The post should have the Title property

  0 passing (6ms)
  1 failing

  1) Test the behavior of Post
       The post should have the Title property:
     ReferenceError: fetch is not defined
      at Object.get (Post.js:6:5)
      at Context.<anonymous> (test/test.js:9:21)

```
