How to use the it function from mocha

Find comprehensive JavaScript mocha.it code examples handpicked from public code repositorys.

127
128
129
130
131
132
133
134
135
136
const { describe, it } = require('mocha');
const { check, gen } = require('mocha-testcheck');
const { expect } = require('chai');

describe('MySpec', () => {
  it('accepts an int', check(gen.int, x => {
    expect(x).to.be.a('number');
  });
});
```
fork icon58
star icon0
watch icon13

11
12
13
14
15
16
17
18
19
20
21
22
const { describe, it } = require('mocha')
const { expect } = require('chai')


describe('decodeHtmlEntity function', function () {


  it('null throws error', async () => {
    const value = null
    await decodeHtmlEntity(value)
      .catch(function (err) {
        expect(function () {
fork icon13
star icon64
watch icon10

+ 164 other calls in file

56
57
58
59
60
61
62
63
64
  expect(utils.equals({first: 1, second: 'both'}, {first: 1, second: 'both'})).to.equal(true);
  expect(utils.equals({first: 1, second: 'both'}, {second: 'both', first: 1})).to.equal(true);
  expect(utils.equals({first: {nest: 1}, second: 'both'}, {second: 'both', first: {nest: 1}})).to.equal(true);
});

it('returns true when comparing unequal arrays', function () {
  expect(utils.equals([1, 2, 3], [3, 1, 2])).to.equal(false);
  expect(utils.equals([{age: 12, height: 50}], [{age: 12, height: 60}])).to.equal(false);
});
fork icon7
star icon23
watch icon16

+ 6 other calls in file

35
36
37
38
39
40
41
42
43
44
>
chai.use(chaiHttp);
>
describe('site', function () {
  // Describe what you are testing
  it('Should have home page', function (done) {
    // Describe what should happen
    // In this case we test that the home page loads
    agent
      .get('/')
fork icon6
star icon22
watch icon4

+ 3 other calls in file

40
41
42
43
44
45
46
47
48
49
it('should aggregate all entries', async () => {
  const result = await cache.aggregate(agg)
  assert.equal(Number(result), 289.5)
})

it('should aggregate filtered entries', async () => {
  const filter = Filters.between('id', 123, 456)
  const result = await cache.aggregate(filter, agg)
  assert.equal(Number(result), 289.5)
})
fork icon7
star icon8
watch icon14

+ 77 other calls in file

13
14
15
16
17
18
19
20
21
22

beforeEach(() => {
  tags.splice(0, tags.length)
})

it('expect a EDOCKERIMAGEPUSH error', async () => {
  try {
    const pluginConfig = createConfig()
    const ctx = createContext()
    await publish(pluginConfig, ctx)
fork icon5
star icon12
watch icon3

+ 11 other calls in file

12
13
14
15
16
17
18
19
20
21
before(() => {
  mock('dockerode', DockerMock)
  verify = require('../src/verify')
})

it('expect a ENOBASEIMAGENAME error', async () => {
  try {
    await verify(pluginConfig, { env })
  } catch (errs) {
    const err = errs._errors[0]
fork icon5
star icon12
watch icon3

+ 23 other calls in file

25
26
27
28
29
30
31
32
33
34
    expect(err.name).to.equal('SemanticReleaseError')
    expect(err.code).to.equal('EDOCKERIMAGETAG')
  }
})

it('expect success prepare', async () => {
  const pluginConfig = createConfig()
  const ctx = createContext()
  pluginConfig.registries[0].imageName = 'registry.example.com/myapp'
  pluginConfig.additionalTags = ['beta']
fork icon5
star icon12
watch icon3

+ 5 other calls in file

87
88
89
90
91
92
93
94
95
96
  } catch (e) {
    expect(e.message).to.equal('No application to deploy.');
  }
});

it('should not deploy without a release tag given', async () => {
  try {
    await scalingoClient.deployFromArchive('pix-app', null);
    expect.fail('Should throw an error when no release tag given');
  } catch (e) {
fork icon4
star icon8
watch icon4

+ 25 other calls in file

48
49
50
51
52
53
54
55
56
57
    expectedBaseUrl: 'https://login.test.com/api',
    expectedError: 'Missing required property "authressLoginHostUrl" in LoginClient constructor. Custom Authress Domain Host is required.'
  };
};
for (let test of tests) {
  it(test.name, () => {
    try {
      const loginClient = new LoginClient({ authressLoginHostUrl: test.url, skipBackgroundCredentialsCheck: true });
      expect(loginClient.httpClient.client.defaults.baseURL).to.eql(test.expectedBaseUrl);
      expect(test.expectedError).to.eql(undefined);
fork icon2
star icon6
watch icon3

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
25
  })
})
afterEach(() => {
  sandbox.restore()
})
it('handles unconventional commit', async () => {
  const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
  sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/unconventional.json')
  await api.main()
  sandbox.assert.notCalled(addLabels)
fork icon2
star icon6
watch icon0

+ 3 other calls in file

0
1
2
3
4
5
6
7
8
9
10
11
//mocha requires


const assert = require("assert");
const mocha = require("mocha");
const describe = mocha.describe;
const it = mocha.it;
const beforeEach = mocha.beforeEach;


//test requires
const s2sMS = require("../src/index");
fork icon0
star icon3
watch icon7

11
12
13
14
15
16
17
18
19
20
    const obj3 = combined;
    combined.t3 = obj3;
    assert.isTrue(ObjectFactory.IsCircular(combined));
    assert.isFalse(ObjectFactory.IsCircular(obj1));
});
it('show Circular References Info', () => {
    const obj1 = {hello:'world',c:null};
    const obj2 = {test:'me',c:obj1};
    obj1.c = obj2;
    const combined = {t1:obj1,t2:obj2,t3:null};
fork icon0
star icon1
watch icon2

+ 110 other calls in file

6
7
8
9
10
11
12
13
14
15
16
const allConfig = [
  environmentConfig,
];


const testEnvParam = (param) => {
  it(param, () => {
    assert.notStrictEqual(process.env[param], undefined, `${param} is not specified`);
  });
};

fork icon0
star icon0
watch icon1

+ 2 other calls in file

9
10
11
12
13
14
15
16
17
18
19
20
21
var agent = chai.request.agent(app);




describe('filtering huts apis', () => {


    it('no filters',done=>{
        agent.post('/api/huts/list').then(res=>{
            res.should.have.status(200);
            expect(res.body.length).equal(1);
            done();
fork icon0
star icon0
watch icon1

+ 5 other calls in file

369
370
371
372
373
374
375
376
377
378
    });
    const merchant = await getMerchant(namespace.merchantGlobalDataId);
    assert(merchant === null);
});

it('should be possible deactivate place and merchant by deactivating product', async () => {
    await activateStore(namespace.firstPlaceJson);
    await activateStore(namespace.secondPlaceJson);

    let agreement = await getAgreement(namespace.merchantGlobalDataId);
fork icon0
star icon0
watch icon1

+ 17 other calls in file

64
65
66
67
68
69
70
71
72
    assert.strictEqual(event[0].returnValues[1], accounts[0]);
    assert.strictEqual(event[0].returnValues[2], inheritanceAddress);
    assert.strictEqual(Number(event[0].returnValues[3]), 1);
});

it("returns the number of deployed inheritances", async () => {
    const count = await factory.methods.getDeployedInheritancesCount().call();
    assert.strictEqual(Number(count), 1);
});
fork icon0
star icon0
watch icon1

+ 140 other calls in file

63
64
65
66
67
68
69
70
71
72
    api.createServer();

    expect(api.createServer.getCall(0).args[0]).to.be.equal(undefined);
});

it("should start the server on createServer method", () => {
    const api = new App();
    const portTest = 6000;

    sandbox.spy(api);
fork icon0
star icon0
watch icon1

+ 29 other calls in file

43
44
45
46
47
48
49
50
51
52

afterEach(() => {
    sandbox.restore();
});

it('should return client by id', async () => {
    const id = "1f671f49-0e3f-442e-b764-f0a4222b5a3e";
    const expected = mocks.validClient;

    const result = await clientService.getClientById(id);
fork icon0
star icon0
watch icon1

+ 16 other calls in file