Giter Club home page Giter Club logo

mokka's People

Contributors

danielr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mokka's Issues

Better support for throwing functions

Throwing functions can currently be mocked like any other function, but we don't support faking errors for throwing function mocks yet.

This could look something like this:

userServiceMock.createUserFunc.throws(UserError.invalidEmail)

Nimble predicates

To better integrate with Nimble, we should provide some basic predicates to make matching nicer.

Something like this:

expect(mock.fooFunc).toNot(beCalled())
expect(mock.barFunc).to(beCalledWith(someArgument))

Native support for callback arguments

Mocking functions with callbacks usually involves calling the callback with configurable arguments. It would be nice, if Mokka could directly support this.

Something like this could work:

public class CallbackFunctionMock<Args, CallbackArgs, CallbackReturnValue>: FunctionMock<Args> {

    var result: CallbackArgs?
    
    public func recordCall(_ args: Args, _ callback: (CallbackArgs) -> CallbackReturnValue) {
        super.recordCall(args)
        
        if let callbackArgs = result {
            _ = callback(callbackArgs)
        }
    }
}

This would then be used like this:

let doSomethingAsyncFunc = CallbackFunctionMock<String, Int, Void>(name: "doSomethingAsync(arg:completion:)")
func doSomethingAsync(arg: String, completion: (Int) -> Void) {
    doSomethingAsyncFunc.recordCall(arg, completion)
}

There are some open questions, though:

  • How to support callbacks with multiple arguments? (Is tuple splat still a thing, or has it been removed in some Swift version?)
  • How to support multiple callbacks?
  • What about functions that have a callback and a return value?
  • Can we somehow get rid of the requirement to separately specify the generic type parameters for the callback arguments and the callback return value? This is not very intuitive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.