Skip to content

Commit

Permalink
Merge pull request #1150 from dbarabashdev/971-action-error-message
Browse files Browse the repository at this point in the history
@action get func(){} have accurate error messages #GoodnessSquadKyiv
  • Loading branch information
mweststrate authored Aug 31, 2017
2 parents 2973fe1 + a92e841 commit 562f935
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ function namedActionDecorator(name: string) {
descriptor.configurable = true
return descriptor
}
if (descriptor !== undefined && descriptor.get !== undefined) {
throw new Error("[mobx] action is not expected to be used with getters");
}
// bound instance methods
return actionFieldDecorator(name).apply(this, arguments)
}
Expand Down
11 changes: 11 additions & 0 deletions test/babel/babel-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ test("babel", function(t) {
t.end()
})

test("should not be possible to use @action with getters", t => {
t.throws(() => {
class A {
@action get Test() { }
}
}, new Error('[mobx] action is not expected to be used with getters'))

mobx.extras.resetGlobalState()
t.end()
})

test("babel: parameterized computed decorator", t => {
class TestClass {
@observable x = 3
Expand Down

0 comments on commit 562f935

Please sign in to comment.