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

Cannot mock 'get name' #15172

Closed
DartBot opened this issue Nov 19, 2013 · 4 comments
Closed

Cannot mock 'get name' #15172

DartBot opened this issue Nov 19, 2013 · 4 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 19, 2013

This issue was originally filed by cvl.c...@gmail.com


Hi!

It is not possible to mock this:

var task = new TaskMock();
task.when(callsTo('get name')).alwaysReturn('test');
print(task.name);

-> prints null.

It conflicts with the internal "Mock" name attribute.

Guess there will be similar problems with the other defined methods and attributes in the Mock class.

@DartBot
Copy link
Author

DartBot commented Nov 19, 2013

This comment was originally written by cvl.chi...@gmail.com


This is a workaround for this case:

class TaskMock implements Task {
  Mock mock = new Mock();
  
  noSuchMethod(Invocation invocation) {
    return mock.noSuchMethod(invocation);
  }
}

Then in testing:
var task = new TaskMock();
task.mock.when(callsTo('get name')).alwaysReturn('test');

@sethladd
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Pkg, Pkg-Mocks, Triaged labels.

@kevmoo
Copy link
Member

kevmoo commented May 9, 2014

Removed Pkg-Mocks label.
Added Pkg-mock label.

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels May 9, 2014
@DartBot
Copy link
Author

DartBot commented Jun 4, 2015

This issue has been moved to dart-archive/mock#3.

@DartBot DartBot closed this as completed Jun 4, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants