-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: move closer to test double definitions #150
Conversation
* test: fix tests and use Deno.test for merging into Rhum v2 * chore: fix comment Co-authored-by: Edward Bebbington <[email protected]>
a14ef67
to
05c66d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg this is beautiful eric, usual minor things but my god the code is sexy
README.md
Outdated
<img src="https://img.shields.io/badge/Tutorials-YouTube-red"> | ||
</a> | ||
</p> | ||
# Drash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAHA dang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doneski: cc0ebdf
extend.js
Outdated
// deno-lint-ignore-file | ||
// This code was bundled using `deno bundle` and it's not recommended to edit it manually | ||
|
||
class Base { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wha dis doing here ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL test files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
donezo: 92bd978
extend.ts
Outdated
@@ -0,0 +1,9 @@ | |||
class Base { | |||
public base_prop = "base prop"; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, test file you committed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dooonnnne: 92bd978
src/mock/mock_mixin.ts
Outdated
////////////////////////////////////////////////////////////////////////////// | ||
// FILE MARKER - CONSTRUCTOR ///////////////////////////////////////////////// | ||
////////////////////////////////////////////////////////////////////////////// | ||
|
||
/** | ||
* @param original - The original object to mock. | ||
* @param methodsToTrack - The original object's method to make trackable. | ||
*/ | ||
public init(original: OriginalObject, methodsToTrack: string[]) { | ||
this.#original = original; | ||
this.#calls = this.#constructCallsProperty(methodsToTrack); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor needs to be updated with methods - public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually that is below so maybe rm that comment block and move method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved them stuffs: 08e47ef
Overview of commits
Updated README
See the new README here.
Refactor and add features to be closer to test double definitions
Test double definitions can be found here: https://martinfowler.com/bliki/TestDouble.html
Currently, we only have:
Still need to add in spies.
Stub()
Before, we created a stub via
Stub(someObject)
and then we could callsomeObject.stub(...)
. This didn't make sense per definition. The definition is:We shouldn't have to call stub on an object to make it stub-able. Instead we should call
Stub(theObjectReceivingTheStub, theDataMemberToStub, optionalValueTheStubShouldReturn)
. API looks like the below now:Use mixin for mock
Introduces using a mixin to create a mock so that calling private methods and returning
this
also works in a mock. For example, the old mock implementation wouldn't work whensomeComplexMethod()
below would returnthis
and callthis.#setSomethingOne()
andthis.#setSomethingTwo()
because the context ofthis
was the mock object and not the original object. It needs to be an instance of the original object. That's where the mixin comes in. Basically, mocks are now extensions of the original so thatmock instanceof original === true
. This approach also fixes the getter/setter issue from https://github.com/drashland/rhum/pull/148/files.Add mock.method(...).willReturn(...)
Add mock.method(...).willThrow(...)
Add mock.expects(...).toBeCalled(...)
Add Fake()
Fakes kind of act like mocks, but they do not have calls and expectations like mocks.
Add Dummy()
Dummies are empty objects of an instance of something. For example,
Dummy(Hello) instanceof Hello === true
. This makes it a little bit easier to fill in parameter lists where parameters must be instances of something.Dummies can also be created without having to specify constructor arguments.