Skip to content
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

Test/add specs #85

Merged
merged 2 commits into from
Jul 19, 2017
Merged

Test/add specs #85

merged 2 commits into from
Jul 19, 2017

Conversation

bfricka
Copy link
Contributor

@bfricka bfricka commented Jul 16, 2017

A few things to note about this PR:

  1. initialState function for features. This was only implemented for root previously, but I added it to features as well. Unfortunately, the implementation is a bit different b/c features aren't using a token to provide initial state.

  2. Removed OpaqueToken. The deps for this project are clear, and we're already using InjectionToken elsewhere, so it doesn't make sense to continue using a deprecated symbol.

  3. Stronger types on core actions INIT, UPDATE, etc. I don't think this actually affects anything currently, but it does make certain inspections nicer.

  4. Watch mode using chokidar. This should make writing development a bit nicer (yarn run watch:tests). This also outputs an html coverage report if that's your cup.

Some of these tests are a bit obtuse. I'm still getting used to writing ng2+ tests, so feedback is welcome if you see something that could be improved. I'll write some more tests in the future, but I wanted to get this out there.

ps: Crossing my fingers that the xit test passes. Last time it failed in CI, and I have zero clue why. If it fails I'll xit back again

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 90.029% when pulling bb489e8 on bfricka:test/add-specs into b9776ea on ngrx:master.

- Add watch:tests for simpler dev / test
- Store utils spec
@bfricka
Copy link
Contributor Author

bfricka commented Jul 18, 2017

Hey there! First off, congrats on 4.0.0!

Second, I resolved conflicts!

@coveralls
Copy link

Coverage Status

Coverage increased (+1.4%) to 89.81% when pulling 7f59f72 on bfricka:test/add-specs into a5aad22 on ngrx:master.

const result = store.select('counter1');

expect(result instanceof Store).toBe(true);
expect(result).toEqual(any(Store));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using instanceof seems like a better check than any(Store)

@@ -183,7 +177,7 @@ describe('ngRx Store', () => {
});

// TODO: Investigate why this is no longer working
xit('should complete if the dispatcher is destroyed', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let this test remain excluded

@@ -0,0 +1,81 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove header text

@@ -51,7 +51,13 @@ export class StoreFeatureModule implements OnDestroy {
@Inject(STORE_FEATURES) private features: StoreFeature<any, any>[],
private reducerManager: ReducerManager
) {
features.forEach(feature => reducerManager.addFeature(feature));
for (let feature of features) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functional approach is preferred over the for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it!

return Object.keys(object)
.filter(key => key !== keyToRemove)
.reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});
const ret: Partial<T> = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to refactor this.

import { withLatestFrom } from 'rxjs/operator/withLatestFrom';
import { scan } from 'rxjs/operator/scan';
import { ActionsSubject } from './actions_subject';
import { Action, ActionReducer } from './models';
import { INITIAL_STATE } from './tokens';
import { ReducerObservable } from './reducer_manager';
import { ScannedActionsSubject } from './scanned_actions_subject';
import { INIT } from './';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add INIT to existing imports from ./actions_subject

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I don't know what you mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 9, add INIT to the existing object

import { ActionsSubject, INIT } from './actions_subject';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, got it. It took me an embarrassingly long time to figure out what you were referring to.

describe(`combineReducers()`, () => {
const s1 = { x: '' };
const s2 = { y: '' };
const r1 = (s = s1, a: any): typeof s1 =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a preference, but make the variable names more descriptive than s and a so they are more readable at glance

@bfricka
Copy link
Contributor Author

bfricka commented Jul 19, 2017

Not sure why Circle failed. Everything runs fine here.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.1%) to 89.665% when pulling 50d55b2 on bfricka:test/add-specs into 920a5f4 on ngrx:master.

- (BREAKING) OpaqueToken -> InjectionToken
- Stronger types for core actions (INIT, UPDATE)
- Add more tests
@coveralls
Copy link

Coverage Status

Coverage increased (+1.1%) to 89.645% when pulling 57130fd on bfricka:test/add-specs into 920a5f4 on ngrx:master.

@brandonroberts
Copy link
Member

LGTM

@brandonroberts brandonroberts merged commit 5e5d7dd into ngrx:master Jul 19, 2017
@bfricka bfricka deleted the test/add-specs branch July 21, 2017 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants