-
Notifications
You must be signed in to change notification settings - Fork 1
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
Arrange/Act organisation/placement #80
Comments
Sorry for such a delay with an answer - I was ill. Full repeat for BaseT:let box = new BlackBox()
box.reset()
box.open()
export const isOpened = box.isOpened
box.reset()
box.open()
box.close()
export const isClosed = box.isClosed
box.open()
box.move()
export const isMakingSounds = box.isMakingSounds It fully repeats your test, but IMO it's not the best way to test this Rewritten in order to be more effective:let box = new BlackBox()
box.open()
export const openedBox = { ...box }
box.move()
export const movedBox = { ...box }
box.close()
export const closedBox = { ...box } I would prefer to test returned values of As a bonus - possible future:There are few tasks in current plan (#11 and #14) that will allow to do something like this: # Initializtion
Just call `BlackBox` with `new` keyword.
'''TypeScript
let box = new BlackBox()
'''
## Reseting
This feature is useful for reusing existing variable as new one, without actual re-initialization. Just use `reset` method
'''TypeScript
box.reset()
'''
### Opening
Before any work with `box` you have to open it:
'''TypeScript
box.open()
export const isOpened = box.isOpened // Output: true
'''
#### Moving
You also can move the box like this:
'''TypeScript
box.move()
export const isMakingSounds = box.isMakingSounds // Output: true
'''
#### Closing
After finishing work with box don't forget to close it:
'''TypeScript
box.close()
export const isClosed = box.isClosed // Output: true
''' This
Code blocks on same level (like |
@ArtemGovorov thanks for your question - its something that should be covered in docs. |
Using This: let box = new BlackBox()
box.reset()
box.open()
export const isOpened = box.isOpened
box.reset()
box.open()
box.close()
export const isClosed = box.isClosed
box.open()
box.move()
export const isMakingSounds = box.isMakingSounds doesn't compete well with other testing frameworks isolated test functions ( For example, an error raised from Another point is, when test structure allows it, testing framework can only run some tests or a single test from a test file. Or run async tests concurrently (like AVA is doing by default), when all async tests in a file can be running at the same time. |
Also, if or when you eventually add some way to isolate tests, then the question is - why should one use baseT and not say Jest with snapshots, or (if snapshots are not enough), then Jest/mocha/Jasmine with a customer |
Test isolation will be added - thank you for pointing this part. And way shown above isn't the only one. One of the other possible options is split-reader.
Existing snapshot mechanism doesn't cover a lot of important cases. It's possible to re-implement mostly all of them (e.g. resolvers, circular links, etc.) and deliver it using something like custom I was one of contributors of ts-jest and saw limitations that this particular test-framework brings. I think it will be difficult to implement (if not impossible) features like #69 or #65 without a lot of changes in core and/or ugly user experience (several flags for each command call and a lot of manual configuration). On other hand it's possible to use assertion libraries or even something like tape inside BaseT. But, to be honest, it wasn't designed for such use case and I need more time to investigate if it has any sense to do so. And about async tests. You may do like this: async function someTestFn() {
// ...
// some test code
// ...
return someResult;
}
export const someResult = someTestFn()
export const somePromise = new Promise((resolve, reject) => {
// ...
// some test code
// ...
resolve(someResult);
}); And these promises will be resolved before writing baseline but right now it'll be made in series. I'll think about making this resolving process parallel. |
Oh, I remembered that previously BaseT resolved function by calling them with no arguments. But I stripped this functionality at all (in this release), because it leaded to problems when function is a class, or instance method, or required some arguments. export async function someAsyncTestFn() {
// ...
// some test code
// ...
return someResult;
}
export function someTestFn() {
// ...
// some test code
// ...
return someSyncResult;
} @ArtemGovorov, what do you think about it? It looks like a good solution that will allow us to avoid additional not very stable heuristics for isolating tests. |
Exporting functions for separating tests is a step forward, however it doesn't seem to provide a way to have a tree of tests with reusable setup/teardown. |
Are you trying to say that stuff like |
If you are trying to build a general purpose unit testing framework+runner that can fully replace Jest/Mocha/Jasmine/etc in one's workflow, then providing some way to express test hooks like Another de-facto "the must" attribute of most testing frameworks these days is providing an easy way to reuse those hooks for a set of tests, ideally without having to write any code for it. In Jest/Mocha/Jasmine it is achieved by structuring tests in a tree of Another concern that I have is that the way baseT suggests to separate the Consider the original code sample that I have shared and the suggested way to do the same in baseT (any of the suggested ways actually): let box = new BlackBox()
box.reset()
box.open()
export const isOpened = box.isOpened
box.reset()
box.open()
box.close()
export const isClosed = box.isClosed
box.reset()
box.open()
box.move()
export const isMakingSounds = box.isMakingSounds As you may see, from the original code it is clear that a black box |
Separation Also, it seems that initially I underestimated value of structuring provided by other test frameworks, and didn't spent enough efforts on md-reader (#11) and split-reader (#12), despite that these features are planned for first stable release. Actually, they both will provide same structuring features and differ only in that what have to be marked - docs with triple-slash comment or code with md code block. Previous sample didn't cover one important planned feature, so next example shows it. # init
To initialize use:
'''TypeScript
// code block one
'''
or
'''TypeScript
// code block two
'''
## usage
First example:
'''TypeScript
// code block one
'''
Second example
'''TypeScript
// code block two
'''
### specific usage
'''TypeScript
// code block for specific usage
'''
### second specific usage
'''TypeScript
// code block for second specific usage
'''
## corner cases
First example:
'''TypeScript
// code block one
'''
Second example
'''TypeScript
// code block two
''' This will create following test cases:
As you can see, different code blocks below one heading will be added to test tree as different branches and code blocks below subheadings will be added to all existing branches. What do you think, implementing this feature is enough for test structuring, or I miss something? P.S. |
Closed in favor of #83, #11 and #12. |
How would you suggest to (re)write the following code in baseT?
The text was updated successfully, but these errors were encountered: