Skip to content

Commit

Permalink
Migrate to Jest for unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Blagoev <blagoevn@vmware.com>
  • Loading branch information
nblagoev committed Apr 6, 2019
1 parent 35addca commit 699f258
Show file tree
Hide file tree
Showing 14 changed files with 2,529 additions and 459 deletions.
2 changes: 1 addition & 1 deletion .vscodeignore
Expand Up @@ -8,7 +8,7 @@ build/**
typings/**
protocol/**
**/src/**
**/out/test/**
**/out/__tests__/**

**/*.ts
**/*.map
Expand Down
Expand Up @@ -3,9 +3,6 @@
* SPDX-License-Identifier: MIT
*/

import { expect } from "chai"
import "mocha"

import { Container } from "../di/Container"

import * as Mocks from "./Mocks"
Expand All @@ -15,43 +12,43 @@
it("Can load class without constructor", () => {
const container = new Container()
const obj = container.get(Mocks.NoConstructor)
expect(obj).to.be.instanceof(Mocks.NoConstructor)
expect(obj).toBeInstanceOf(Mocks.NoConstructor)
})

it("Can load class with more params", () => {
const container = new Container()
const obj = container.get(Mocks.WithOneParam)
expect(obj).to.be.instanceof(Mocks.WithOneParam)
expect(obj.p).to.be.instanceof(Mocks.NoConstructor)
expect(obj.p).to.equal(obj.second)
expect(obj).toBeInstanceOf(Mocks.WithOneParam)
expect(obj.p).toBeInstanceOf(Mocks.NoConstructor)
expect(obj.p).toEqual(obj.second)
})

it("Should throw circular dep exception", () => {
const container = new Container()
expect(() => {
container.get(Mocks.C1)
}).to.throw()
}).toThrow()
})

it("Should throw on not annotated class", () => {
const container = new Container()
expect(() => {
container.get(Mocks.NotAutoWired)
}).to.throw()
}).toThrow()
})

it("Should not throw if the instance was aready set", () => {
const container = new Container()
container.set(Mocks.NotAutoWired, new Mocks.NotAutoWired())
expect(() => {
container.get(Mocks.NotAutoWired)
}).not.to.throw()
}).not.toThrow()
})

it("Should throw if constructor has interface type", () => {
const container = new Container()
expect(() => {
container.get(Mocks.IntInConst)
}).to.throw()
}).toThrow()
})
})
File renamed without changes.

0 comments on commit 699f258

Please sign in to comment.