Coder Social home page Coder Social logo

Mock SupabaseClient. about supabase-dart HOT 7 CLOSED

supabase avatar supabase commented on September 23, 2024 4
Mock SupabaseClient.

from supabase-dart.

Comments (7)

BLipscomb avatar BLipscomb commented on September 23, 2024 2

I was wondering about building something like a mock supabase client for my tests, but it was an up-hill battle for me. I moved my database calls to a layer that just talks to the database. For example, I have a dbInsert method that I pass a table name and some records. This method is very simple and just does an insert. My business logic contains a call to dbInsert, and I can easily mock this call in my test.

from supabase-dart.

phamhieu avatar phamhieu commented on September 23, 2024 1

Hi @happy-san, postgrest-dart uses http package so you can use MockClient to write your unit test.

client.from('todos').select('task, status').execute() will translate into https://supabase-url/todos?select=task,status

You can use MockClient to return a json response for that url.

from supabase-dart.

phamhieu avatar phamhieu commented on September 23, 2024 1

Sorry for confusing you with the word MockClient. I create an example here

from supabase-dart.

happy-san avatar happy-san commented on September 23, 2024

Hey, @phamhieu have you considered this?

from supabase-dart.

happy-san avatar happy-san commented on September 23, 2024

Thanks, I'll try it out.

@phamhieu If I'm following you correctly, you're referring to this, right?

But wouldn't mocking only work if the execute() function accepted a client? Like,

  Future<PostgrestResponse> execute({
    bool head = false,
    CountOption? count,
    http.Client client,
  }) 

from supabase-dart.

happy-san avatar happy-san commented on September 23, 2024

Thank you for creating an example. Didn't know that a MockServer could be created, awesome!

from supabase-dart.

fimaljo-inunity avatar fimaljo-inunity commented on September 23, 2024

_instance._initialized': You must initialize the supabase instance before calling Supabase. how to solve this this error showing while unit test and we using supabase only for aythentication and access token

from supabase-dart.

Related Issues (20)

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.