dart-archive / mock

A library for mocking classes - DEPRECATED
https://pub.dartlang.org/packages/mock
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Cannot mock 'get name' #3

Open DartBot opened 9 years ago

DartBot commented 9 years ago

Originally opened as dart-lang/sdk#15172

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 commented 9 years ago

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');

DartBot commented 9 years ago

Comment by sethladd


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

DartBot commented 9 years ago

Comment by kevmoo


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