mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

Moving from mobx 3.2.2 to 3.3.1 broke something #48

Closed marcoturi closed 6 years ago

marcoturi commented 6 years ago

I'm using mobx in an ionic project. My Deps:

"@angular/common": "5.0.0",
        "@angular/compiler": "5.0.0",
        "@angular/compiler-cli": "5.0.0",
        "@angular/core": "5.0.0",
        "@angular/forms": "5.0.0",
        "@angular/http": "5.0.0",
        "@angular/platform-browser": "5.0.0",
        "@angular/platform-browser-dynamic": "5.0.0",
        "@compodoc/compodoc": "1.0.4",
        "@ionic-native/app-version": "4.4.2",
        "@ionic-native/core": "4.4.2",
        "@ionic-native/device": "4.4.2",
        "@ionic-native/local-notifications": "4.4.2",
        "@ionic-native/social-sharing": "4.4.2",
        "@ionic-native/splash-screen": "4.4.2",
        "@ionic-native/status-bar": "4.4.2",
        "@ionic/storage": "2.1.3",
         ...
        "core-js": "^2.4.1",
        "date-fns": "1.29.0",
        "es6-promise-plugin": "4.1.1",
        "ionic-angular": "3.9.2",
        "ionicons": "3.0.0",
        "lodash-es": "4.17.4",
        "mobx": "3.3.1",
        "mobx-angular": "1.9.0",
        "mobx-remotedev": "0.2.8",
        "pouchdb": "6.3.4",
        "raven-js": "3.20.1",
        "rxjs": "5.5.2",
        "sw-toolbox": "3.6.0",
        "waaclock": "0.5.3",
        "zone.js": "0.8.18"

After upgrading mobx 3.2.2 to 3.3.1, 7 tests of the 203 unit tests in my app are broken. An example of broken test after the upgrade:


 it('Should return 1 after first answer', () => {
            exerciseModel.questions[0].answer = 'p2';
            exerciseModel.questions[1].answer = 'p1';
            expect(exerciseModel.questions[0].hasAnswer).toBeTruthy();
            expect(exerciseModel.lastQuestionAnswered).toBe(1);
        });

export class ExerciseModel implements Exercise {
    @observable public questions: QuestionModel[];
    @computed
    public get lastQuestionAnswered(): number {
        const result = findLastIndex(this.questions, 'hasAnswer');
        return result === -1 ? 0 : result;
    }
   //....
}

export class QuestionModel {
    @observable public hasAnswer: boolean = false;
    @observable public isOpen: boolean;
    @observable private _answer: any = null;
   //....
@computed
    public get answer(): any {
        if (this._answer == null) {
            switch (this.answerType) {
                case 'textarea':
                    this._answer = '';
                    break;
                case 'range':
                    this._answer = 5;
                    break;
                case 'none':
                    this._answer = '';
                    break;
                default:
                    this._answer = '';
            }
        }

        return this._answer;
    }

    public set answer(val: any) {
        if (val != null) {
            this._answer = val;
            this.hasAnswer = true;
        }
    }
}
adamkleingit commented 6 years ago

Hi, what is broken? What is the complete error message? Does the app work and it's just the tests that fail?

marcoturi commented 6 years ago

@adamkleingit This afternoon i'll send you the error message. The app does not work also.

marcoturi commented 6 years ago

here are the stack traces:

✖ Should return 1 after first answer
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) Exercise Model: .lastQuestionAnswered Should return 1 after first answer FAILED
    Expected false to be truthy.
        at UserContext.<anonymous> (webpack:///src/core/services/exercises/models/exercise.model.spec.ts:32:0 <- config/karma-shim.js:174327:58)
        at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:392:0 <- config/karma-shim.js:132240:26)
        at ProxyZoneSpec.onInvoke (webpack:///node_modules/zone.js/dist/proxy.js:79:0 <- config/karma-shim.js:135141:39)
        at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:391:0 <- config/karma-shim.js:132239:32)
        at Zone.run (webpack:///node_modules/zone.js/dist/zone.js:142:0 <- config/karma-shim.js:131990:43)
        at UserContext.<anonymous> (webpack:///node_modules/zone.js/dist/jasmine-patch.js:104:0 <- config/karma-shim.js:135349:34)
        at ZoneQueueRunner.jasmine.QueueRunner.ZoneQueueRunner.execute (webpack:///node_modules/zone.js/dist/jasmine-patch.js:132:0 <- config/karma-shim.js:135377:42)
        at ZoneDelegate.invokeTask (webpack:///node_modules/zone.js/dist/zone.js:425:0 <- config/karma-shim.js:132273:31)
        at Zone.runTask (webpack:///node_modules/zone.js/dist/zone.js:192:0 <- config/karma-shim.js:132040:47)
        at drainMicroTaskQueue (webpack:///node_modules/zone.js/dist/zone.js:602:0 <- config/karma-shim.js:132450:35)
        at <anonymous>
    Expected 0 to be 1.
        at UserContext.<anonymous> (webpack:///src/core/services/exercises/models/exercise.model.spec.ts:33:0 <- config/karma-shim.js:174328:56)
        at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:392:0 <- config/karma-shim.js:132240:26)
        at ProxyZoneSpec.onInvoke (webpack:///node_modules/zone.js/dist/proxy.js:79:0 <- config/karma-shim.js:135141:39)
        at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:391:0 <- config/karma-shim.js:132239:32)
        at Zone.run (webpack:///node_modules/zone.js/dist/zone.js:142:0 <- config/karma-shim.js:131990:43)
        at UserContext.<anonymous> (webpack:///node_modules/zone.js/dist/jasmine-patch.js:104:0 <- config/karma-shim.js:135349:34)
        at ZoneQueueRunner.jasmine.QueueRunner.ZoneQueueRunner.execute (webpack:///node_modules/zone.js/dist/jasmine-patch.js:132:0 <- config/karma-shim.js:135377:42)
        at ZoneDelegate.invokeTask (webpack:///node_modules/zone.js/dist/zone.js:425:0 <- config/karma-shim.js:132273:31)
        at Zone.runTask (webpack:///node_modules/zone.js/dist/zone.js:192:0 <- config/karma-shim.js:132040:47)
        at drainMicroTaskQueue (webpack:///node_modules/zone.js/dist/zone.js:602:0 <- config/karma-shim.js:132450:35)
        at <anonymous>
marcoturi commented 6 years ago

I made a repo to reproduce the error: https://github.com/marcoturi/ionic-boilerplate-mobx-error

git clone https://github.com/marcoturi/ionic-boilerplate-mobx-error.git

npm i/yarn + yarn/npm test -> this will show the error Go to package.json and change mobx version to 3.2.2, then npm i/yarn + yarn/npm test -> no errors

Hope it helps to debug.

adamkleingit commented 6 years ago

Hi, I just realized this issue has nothing to do with mobx-angular. Can you please open it in mobx repo?