Skip to content

Resetting with CallBase = true will not fallback to base class #135

Open
@BobHemphill

Description

        it.only("call base reset fails", () => {
		class MockMe {
			public a() {
				return 5;
			}
		}

		const mockMeMock: TypeMoq.IMock<MockMe> = TypeMoq.Mock.ofInstance(new MockMe());
		mockMeMock.callBase = true;

		mockMeMock.setup((mm) => mm.a()).returns(() => 10);
		chai.assert.equal(mockMeMock.object.a(), 10);
		chai.assert.equal(mockMeMock.object.a(), 10);
		chai.assert.equal(mockMeMock.object.a(), 10);

		mockMeMock.reset();
		chai.assert.equal(mockMeMock.object.a(), 5); // FAILS
	});

	it.only("call base false reset succeeds", () => {
		class MockMe {
			public a() {
				return 5;
			}
		}

		const mockMeMock: TypeMoq.IMock<MockMe> = TypeMoq.Mock.ofInstance(new MockMe());
		mockMeMock.callBase = false;

		mockMeMock.setup((mm) => mm.a()).returns(() => 10);
		chai.assert.equal(mockMeMock.object.a(), 10);
		chai.assert.equal(mockMeMock.object.a(), 10);
		chai.assert.equal(mockMeMock.object.a(), 10);

		mockMeMock.reset();
		chai.assert.isUndefined(mockMeMock.object.a()); // PASSES
	});

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions